[ComposedModal] keyboard trap fails when modal is last component in page
See original GitHub issueWhat package(s) are you using?
-
carbon-components
-
carbon-components-react
Detailed description
In normal use, a ComposedModal will trap the keyboard to rotate the input focus within the modal itself. If you add a ComposedModal as the last component in a page i.e. there are no naturally focusable elements in the DOM after the modal, then the focus trap fails to work.
The reason this fails to work is that the focus moves to the browser URL bar which is a non-DOM element so the evt.relatedTarget
value in the focus event is set to null
for security reasons. The handleBlur
function will not work if evt.relatedTarget
is null, so the keyboard trap fails.
This occurs in both Firefox and Chrome.
Steps to reproduce the issue
- Build a page with some focusable elements
- Add a ComposedModal at the end of the page
- Show the modal and press Tab to move the focus.
- Observe that the focus is not trapped and actually follows through the browser URL bar and then the rest of the page.
- Move the modal to the start of the page and observe that the focus trap now works.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Understanding Success Criterion 2.1.2: No Keyboard Trap | WAI
Intent. The intent of this Success Criterion is to ensure that that content does not "trap" keyboard focus within subsections of content on...
Read more >Keyboard trap when using ctools modal [#2280853] | Drupal.org
Keyboard users who attempt to use the Panels IPE (or Page Manager, ... within the modal, so tabbing forward after the last focusable...
Read more >How to trap focus inside modal to make it ADA compliant
tab, shift + tab and enter key and focus should be trapped inside modal and should not go out after pressing tab key...
Read more >accessibility-guidelines - No keyboard trap - GitHub Pages
A modal dialogue opens but cannot be closed with the keyboard, preventing the user from accessing the original content underneath;; Content is presented...
Read more >Modals and Keyboard Traps - YouTube
Check out all of Udacity's courses at https://www.udacity.com/courses.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I find it odd that this is intentional. Adding a check for a null value for
evt.relatedTarget
should be all that is needed to fix this issue. A null value will always indicate that the newly focussed item is outside the scope of the modal so it is safe to call thefocusModal
method in this case.I see your points, consideration is in place for better documentation, etc as well as better announcement. We are aware that there are two choices on focus-wrap, and took a route with less implementation overhead.