-
Notifications
You must be signed in to change notification settings - Fork 538
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
ActionList: Enable focusZone for roles listbox and menu #4795
Changes from all commits
fe152fe
7fd4091
2c242bf
70e39f6
2eda6fe
fa13d5a
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: Enable focusZone for roles listbox and menu |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,19 +33,25 @@ export const List = React.forwardRef<HTMLUListElement, ActionListProps>( | |
|
||
/** if list is inside a Menu, it will get a role from the Menu */ | ||
const { | ||
listRole, | ||
listRole: listRoleFromContainer, | ||
listLabelledBy, | ||
selectionVariant: containerSelectionVariant, // TODO: Remove after DropdownMenu2 deprecation | ||
enableFocusZone, | ||
enableFocusZone: enableFocusZoneFromContainer, | ||
} = React.useContext(ActionListContainerContext) | ||
|
||
const ariaLabelledBy = slots.heading ? slots.heading.props.id ?? headingId : listLabelledBy | ||
|
||
const listRole = role || listRoleFromContainer | ||
const listRef = useProvidedRefOrCreate(forwardedRef as React.RefObject<HTMLUListElement>) | ||
|
||
let enableFocusZone = false | ||
if (enableFocusZoneFromContainer !== undefined) enableFocusZone = enableFocusZoneFromContainer | ||
else if (listRole) enableFocusZone = ['menu', 'menubar', 'listbox'].includes(listRole) | ||
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. Non-blocking: I see we have have 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 one yet, but I think it's possible. The issue linked to menu + menubar pattern, so I included it just in case |
||
|
||
useFocusZone({ | ||
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. I'm wondering if we'd want to add 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.
Honestly, not sure, what do you think?
That's the part that's missing right now. I think I'd like to wait for feedback/requests before introducing 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. For 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. Done! |
||
disabled: !enableFocusZone, | ||
containerRef: listRef, | ||
bindKeys: FocusKeys.ArrowVertical | FocusKeys.HomeAndEnd | FocusKeys.PageUpDown, | ||
focusOutBehavior: listRole === 'menu' ? 'wrap' : undefined, | ||
}) | ||
|
||
return ( | ||
|
@@ -54,14 +60,14 @@ export const List = React.forwardRef<HTMLUListElement, ActionListProps>( | |
variant, | ||
selectionVariant: selectionVariant || containerSelectionVariant, | ||
showDividers, | ||
role: role || listRole, | ||
role: listRole, | ||
headingId, | ||
}} | ||
> | ||
{slots.heading} | ||
<ListBox | ||
sx={merge(styles, sxProp as SxProp)} | ||
role={role || listRole} | ||
role={listRole} | ||
aria-labelledby={ariaLabelledBy} | ||
{...props} | ||
ref={listRef} | ||
|
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.
If there's an existing focus zone being used for an
ActionList
, would the one being used here replace it? I saw an instance where there was anActionList
inside of anAnchoredOverlay
that had an implicit focus zone attached:I'm wondering if this would be an issue or not 🤔. I think the existing cases are rare, so doesn't seem like it would be.
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.
focus zones can only be additive, not removed. So, if the parent AnchoredOverlay has a focus zone, that would work on all its children. Setting it to false on ActionList would not exclude it from the parent's focus zone.
Tested with ActionMenu, Autocomplete, etc. because they also use AnchoredOverlay (and it's focus zone)