-
Notifications
You must be signed in to change notification settings - Fork 614
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
Changes from all commits
460be86
88408c5
9ff0372
89a5e0e
45a8796
2550b5b
b0468d7
02c62a9
626ccad
9994fa4
0750e4a
9660adc
2ead1e4
6381618
84aaff8
File filter
Filter by extension
Conversations
Jump to
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'] | ||
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, 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.