[a11y] Modal focus state
Issue copied from: https://github.com/Shopify/web/issues/6153
Issue summary
There are some small issues with how modals are handled for keyboard users, including screen reader users.
When a modal opens, its container is next in the tab order, but it does not receive focus when it opens. As a result, non-visual screen reader users may not be able to tell what has happened. While a modal is open, it's possible to tab to the Skip to Content button at the top of the DOM. Some modal paradigms allow focus to go to the browser chrome, but it shouldn't go to content "under" the modal.
Behavior (tl;dr)
Expected
- Focus will move to the modal when it opens.
- Focus will not move to content "under" the modal.
Actual
- Focus does not move to the modal when it opens.
- Focus can move to the
Skip to Contentbutton.
Recommendations
- When the modal opens, send focus to the modal container immediately.
- Prevent focus from going to content outside the modal. The Rails modal kept focus out of the chrome as well, which seems to be the standard in admin.
Specifications
- Component: #6014
- WCAG SCs: 2.4.3 Focus Order (Level A)
- Testing done with: Keyboard, VoiceOver with Safari on macOS, NVDA with Firefox on Windows 10
@maxariss I'm considering combining this issue with https://github.com/Shopify/polaris-react-deprecated/issues/1610, in this repo. What do you think?
Closing in favor of https://github.com/Shopify/polaris-react/issues/795, which includes other modal issues.