Skip to content

Commit 9ee8ec9

Browse files
authored
Fix ActionList.Item conditional when FF is not enabled (#4695)
* Fix conditional when FF is not enabled * Add changeset
1 parent db72a71 commit 9ee8ec9

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

.changeset/modern-cooks-decide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
Fixes conditional in `ActionList.Item` that was dependent on FF being active before applying forwarded ref.

packages/react/src/ActionList/ActionList.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,34 @@ describe('ActionList', () => {
426426
expect(listItems.length).toBe(2)
427427
})
428428

429+
it('should apply ref to ActionList.Item when feature flag is disabled', async () => {
430+
const MockComponent = () => {
431+
const ref = React.useRef<HTMLLIElement>(null)
432+
433+
const focusRef = () => {
434+
if (ref.current) ref.current.focus()
435+
}
436+
437+
return (
438+
<FeatureFlags flags={{primer_react_action_list_item_as_button: false}}>
439+
<button onClick={focusRef}>Prompt</button>
440+
<ActionList>
441+
<ActionList.Item ref={ref}>Item 1</ActionList.Item>
442+
<ActionList.Item>Item 2</ActionList.Item>
443+
</ActionList>
444+
</FeatureFlags>
445+
)
446+
}
447+
448+
const {getByRole} = HTMLRender(<MockComponent />)
449+
const triggerBtn = getByRole('button', {name: 'Prompt'})
450+
const focusTarget = getByRole('listitem', {name: 'Item 1'})
451+
452+
fireEvent.click(triggerBtn)
453+
454+
expect(document.activeElement).toBe(focusTarget)
455+
})
456+
429457
it('should render ActionList.Item as li when feature flag is enabled and has proper aria role', async () => {
430458
const {container} = HTMLRender(
431459
<FeatureFlags flags={{primer_react_action_list_item_as_button: false}}>

packages/react/src/ActionList/Item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
368368
value={{variant, disabled, inactive: Boolean(inactiveText), inlineDescriptionId, blockDescriptionId}}
369369
>
370370
<LiBox
371-
ref={buttonSemanticsFeatureFlag || listSemantics ? forwardedRef : null}
371+
ref={!buttonSemanticsFeatureFlag || listSemantics ? forwardedRef : null}
372372
sx={
373373
buttonSemanticsFeatureFlag
374374
? merge<BetterSystemStyleObject>(

0 commit comments

Comments
 (0)