-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 issue with top bar menu having unique ARIA roles #13059
Changes from all commits
001a3f3
a42e5d6
75fc100
7811b8f
7f9ea08
874ab92
92e4ef4
ac8eb39
7bf8a34
c58588b
13120e6
2517c36
a47ea27
d99dbb7
ae906f4
c52db84
be2b57c
0ea3031
a123632
8eabcbf
264510e
b23da67
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 |
---|---|---|
|
@@ -19,6 +19,9 @@ export function MenuGroup( { | |
className = '', | ||
instanceId, | ||
label, | ||
role = 'menu', | ||
useEventToOffset = true, | ||
Firestorm980 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isLabelHidden = false, | ||
} ) { | ||
if ( ! Children.count( children ) ) { | ||
return null; | ||
|
@@ -33,9 +36,17 @@ export function MenuGroup( { | |
return ( | ||
<div className={ classNames }> | ||
{ label && | ||
<div className="components-menu-group__label" id={ labelId }>{ label }</div> | ||
<div | ||
className={ classnames( 'components-menu-group__label', { | ||
hidden: isLabelHidden, | ||
} ) } | ||
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. see above |
||
id={ labelId } | ||
aria-hidden={ ( role === 'group' ) } | ||
> | ||
{ label } | ||
</div> | ||
} | ||
<NavigableMenu orientation="vertical" aria-labelledby={ label ? labelId : null }> | ||
<NavigableMenu orientation="vertical" aria-labelledby={ label ? labelId : null } role={ role } useEventToOffset={ useEventToOffset }> | ||
{ children } | ||
</NavigableMenu> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -68,6 +68,11 @@ class NavigableContainer extends Component { | |||||
const { getFocusableContext } = this; | ||||||
const { cycle = true, eventToOffset, onNavigate = noop, stopNavigationEvents } = this.props; | ||||||
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.
Suggested change
This should be enough to make this work instead of the check:
|
||||||
|
||||||
// This avoids a console error when eventToOffset is null | ||||||
if ( ! eventToOffset ) { | ||||||
return; | ||||||
} | ||||||
|
||||||
const offset = eventToOffset( event ); | ||||||
|
||||||
// eventToOffset returns undefined if the event is not handled by the component | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import WritingMenu from '../writing-menu'; | |
|
||
const ariaClosed = __( 'Show more tools & options' ); | ||
const ariaOpen = __( 'Hide more tools & options' ); | ||
const menuLabel = __( 'Tools & Options' ); | ||
|
||
const MoreMenu = () => ( | ||
<Dropdown | ||
|
@@ -33,11 +34,12 @@ const MoreMenu = () => ( | |
) } | ||
renderContent={ ( { onClose } ) => ( | ||
<Fragment> | ||
<WritingMenu onClose={ onClose } /> | ||
<ModeSwitcher onSelect={ onClose } /> | ||
<PluginMoreMenuGroup.Slot fillProps={ { onClose } } /> | ||
<ToolsMoreMenuGroup.Slot fillProps={ { onClose } } /> | ||
<MenuGroup> | ||
<MenuGroup label={ menuLabel } isLabelHidden={ true }> | ||
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.
|
||
<WritingMenu onClose={ onClose } /> | ||
<ModeSwitcher onSelect={ onClose } /> | ||
<PluginMoreMenuGroup.Slot fillProps={ { onClose } } /> | ||
<ToolsMoreMenuGroup.Slot fillProps={ { onClose } } /> | ||
|
||
<OptionsMenuItem onSelect={ onClose } /> | ||
</MenuGroup> | ||
</Fragment> | ||
|
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.
It feels wrong to see the default role set
menu
for the component which is calledMenuGroup
and then see it overridden back togroup
in other places. It seems like we need to introduce another component calledMenu
which will haverole
set tomenu
, its class name which will hide the label for the menu, and will always haveuseEventToOffset
set totrue
. This will make it possible to leaveMenuGroup
usage unchanged.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.
@gziolo should we spin up a new issue for that?
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 would feel comfortable doing it as part of this PR because in the current form you might see unexpected
role="menu"
in all plugins usingMenuGroup
.