Menu: close the dropdown on Tab (WAI-ARIA menu button pattern) #9409
kiril-learnwise
started this conversation in
Feature requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi,
An accessibility audit of our app flagged that Tab cannot leave an open Menu (WCAG 2.4.3 Focus Order): the dropdown traps focus, and with
menuItemTabIndex={0}Tab only cycles through the items. The WAI-ARIA menu button pattern expects Tab to close the menu and move to the next element in the tab sequence, with the arrow keys moving between items.The navigation recipe from the docs (
trapFocus={false},withinPortal={false},menuItemTabIndex={0}) doesn't fit action menus: every item becomes a tab stop, the dropdown stays open after focus leaves it (so it can cover the newly focused control), and we can't render the dropdown inline in a clipped header. With the default portal,trapFocus={false}sends Tab to the end of<body>.Right now we get this by controlling opened and handling Tab in Menu.Dropdown's onKeyDown, plus suppressing returnFocus for that close so useFocusReturn doesn't pull focus back to the target.
Would you be open to supporting this in Menu as an opt-in prop?
The implementation is small: MenuDropdown focuses the target and closes the dropdown on Tab, without preventing the default action, so the browser continues the tab sequence from the target as if the portalled dropdown wasn't there. Its own tab order then applies (positive tabindex, radio groups, shadow DOM). Shift + Tab prevents the default and stays on the target. Submenus close with the root menu, as the pattern specifies.
I have this working on a branch with tests (Tab, Shift + Tab, Tab from a non-first item, unchanged default) and docs (keyboard table rows and a paragraph next to the menuItemTabIndex note). Happy to open a PR if this direction works for you.
My research on this issue found only #5077, but it's not related:
This is not a request to make items tabbable (#5077). It is the Tab row of the menu button pattern: the menu stays a single tab stop, and Tab leaves it instead of being trapped.
All reactions