Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ActionList.Item conditional when FF is not enabled #4695

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/modern-cooks-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Fixes conditional in `ActionList.Item` that was dependent on FF being active before applying forwarded ref.
28 changes: 28 additions & 0 deletions packages/react/src/ActionList/ActionList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,34 @@ describe('ActionList', () => {
expect(listItems.length).toBe(2)
})

it('should apply ref to ActionList.Item when feature flag is disabled', async () => {
const MockComponent = () => {
const ref = React.useRef<HTMLLIElement>(null)

const focusRef = () => {
if (ref.current) ref.current.focus()
}

return (
<FeatureFlags flags={{primer_react_action_list_item_as_button: false}}>
<button onClick={focusRef}>Prompt</button>
<ActionList>
<ActionList.Item ref={ref}>Item 1</ActionList.Item>
<ActionList.Item>Item 2</ActionList.Item>
</ActionList>
</FeatureFlags>
)
}

const {getByRole} = HTMLRender(<MockComponent />)
const triggerBtn = getByRole('button', {name: 'Prompt'})
const focusTarget = getByRole('listitem', {name: 'Item 1'})

fireEvent.click(triggerBtn)

expect(document.activeElement).toBe(focusTarget)
})

it('should render ActionList.Item as li when feature flag is enabled and has proper aria role', async () => {
const {container} = HTMLRender(
<FeatureFlags flags={{primer_react_action_list_item_as_button: false}}>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/ActionList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>(
value={{variant, disabled, inactive: Boolean(inactiveText), inlineDescriptionId, blockDescriptionId}}
>
<LiBox
ref={buttonSemanticsFeatureFlag || listSemantics ? forwardedRef : null}
ref={!buttonSemanticsFeatureFlag || listSemantics ? forwardedRef : null}
sx={
buttonSemanticsFeatureFlag
? merge<BetterSystemStyleObject>(
Expand Down
Loading