Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 678
ActionList: Add more checks for ActionList.Item when using button semantics#4876
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
460be8688408c59ff037289a5e0e45a87962550b5bb0468d702c62a9626ccad9994fa40750e4a9660adc2ead1e4638161884aaff8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': patch | ||
| --- | ||
| ActionList: Add more guards for `ActionList.Item` before utilizing button semantics (behind feature flag `primer_react_action_list_item_as_button`) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -24,6 +24,14 @@ import VisuallyHidden from '../_VisuallyHidden' | ||
| const LiBox = styled.li<SxProp>(sx) | ||
| const ButtonItemContainer = React.forwardRef(({as: Component = 'button', children, styles, ...props}, forwardedRef) => { | ||
| return ( | ||
| <Box as={Component as React.ElementType} ref={forwardedRef} sx={styles} {...props}> | ||
| {children} | ||
| </Box> | ||
| ) | ||
| }) as PolymorphicForwardRefComponent<React.ElementType, ActionListItemProps> | ||
| export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | ||
| ( | ||
| { | ||
| @@ -112,7 +120,12 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | ||
| const itemSelectionAttribute = selectionAttribute || inferredSelectionAttribute | ||
| // Ensures ActionList.Item retains list item semantics if a valid ARIA role is applied, or if item is inactive | ||
| const listSemantics = listRole === 'listbox' || listRole === 'menu' || inactive || container === 'NavList' | ||
| const listItemSemantics = | ||
| role === 'option' || role === 'menuitem' || role === 'menuitemradio' || role === 'menuitemcheckbox' | ||
| const listRoleTypes = ['listbox', 'menu', 'list'] | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oooh, MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have any live cases of Not really beholden to having it here, but thought it could be useful as a escape hatch for components that still need the old semantics, at least temporarily. | ||
| const listSemantics = | ||
| (listRole && listRoleTypes.includes(listRole)) || inactive || container === 'NavList' || listItemSemantics | ||
| const buttonSemantics = !listSemantics && !_PrivateItemWrapper && buttonSemanticsFeatureFlag | ||
| const {theme} = useTheme() | ||
| @@ -268,22 +281,9 @@ export const Item = React.forwardRef<HTMLLIElement, ActionListItemProps>( | ||
| const trailingVisualId = `${itemId}--trailing-visual` | ||
| const inactiveWarningId = inactive && !showInactiveIndicator ? `${itemId}--warning-message` : undefined | ||
| const ButtonItemWrapper = React.forwardRef(({as: Component = 'button', children, ...props}, forwardedRef) => { | ||
| return ( | ||
| <Box | ||
| as={Component as React.ElementType} | ||
| sx={merge<BetterSystemStyleObject>(styles, sxProp)} | ||
| ref={forwardedRef} | ||
| {...props} | ||
| > | ||
| {children} | ||
| </Box> | ||
| ) | ||
| }) as PolymorphicForwardRefComponent<React.ElementType, ActionListItemProps> | ||
| let DefaultItemWrapper = React.Fragment | ||
| if (buttonSemanticsFeatureFlag) { | ||
| DefaultItemWrapper = listSemantics ? React.Fragment : ButtonItemWrapper | ||
| DefaultItemWrapper = listSemantics ? React.Fragment : ButtonItemContainer | ||
| } | ||
| const ItemWrapper = _PrivateItemWrapper || DefaultItemWrapper | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just checking, do we need to merge styles like ButtonItemWrapper or is that not needed anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw we were already handling this on line #329, so now we pass the same logic to
ButtonItemContainer, but under the styles prop instead of handling it inside of the component.