Concerned about Dropdown Menu's modal accessibility
See original GitHub issueBug report
By default, Dropdown Menu uses a modal mode (modal=true
), which prevents keyboard and/or screen-reader users from ever accessing content outside <DropdownMenuContent>
without first selecting a <DropdownMenuItem>
.
You state that you adhere to the Menu Button WAI-ARIA design pattern, however, this pattern never mentions that a user should be trapped within the dropdown, and indeed, their examples freely let users not interact with an open dropdown should they wish.
FWIW, setting modal={false}
on your Codesandbox demo also seems to have no effect either, but I could be doing something wrong…
Current Behavior
- A keyboard user tabs on to the button
- They press Enter or Space to open the menu
- They decide they don’t want to interact with it
- They can’t (shift) tab out of it to other content on the page, nor to the
<DropdownMenuTrigger>
to close it again with Enter or Space (unless they press Escape)
The same goes for screen reader users who navigate with their previous and next commands. They are also trapped within the dropdown.
Expected behavior
Dropdowns are non-modal and are allowed to be ignored when opened. Users should be free to access content before or after it without closing it, or to be able to reach the <DropdownMenuTrigger>
to close it, just as mouse users can.
Reproducible example
Suggested solution
Remove the modal implementation and remove the <DropdownMenuContent>
from being within a portal so a keyboard user’s (shift) tab key and a screen reader user’s previous and next commands actually take them to the relevant previous and next elements in the page.
I understand that not using a portal may present other issues (such as being clipped by overflow
or z-index
), however, I don’t know of any other way to maintain the document order for screen-reader users using previous and next (tab can be hacked around).
Additional context
The Menu WAI-ARIA pattern explicitly states:
Tab: Moves focus to the next element in the tab sequence, and if the item that had focus is not in a menubar, closes its menu and all open parent menu containers. Shift + Tab: Moves focus to the previous element in the tab sequence, and if the item that had focus is not in a menubar, closes its menu and all open parent menu containers.
Your environment
Software | Name(s) | Version |
---|---|---|
Radix Package(s) | @radix-ui/react-dropdown-menu | 0.1.0 |
React | n/a | 17.0.2 |
Browser | Chrome | 93.0.4577.82 |
Assistive tech | VoiceOver | |
Operating System | Mac |
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Accidentally stumbled across some things that will help us solve this. Created a PoC here for when we’re ready to pick this up https://github.com/radix-ui/primitives/compare/popover-no-loop...non-modal-a11y
Thanks for the prompt reply. It’s good to see that with a combination of
modal={false}
andportalled={false}
that you can get the dropdown much closer to spec. I would strongly encourage you to make this the default, or at a minimum call it out clearly in the docs.While I agree that some of the more complex components and pattern specs aren’t 100% perfect, the accessibility community is pretty much agreed upon the keyboard behaviour of such a rudimentary component like Menu Button. Here are a few examples I quickly found which all contain the correct tab behaviour (and some even explictly mention it):
Ah, so that’s why I thought
modal={false}
wasn’t doing anything.At a bare minimum this needs to be implemented, but I would strongly encourage full Tab support, especially when combining
modal={false}
andportalled={false}