question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ComposedModal] keyboard trap fails when modal is last component in page

See original GitHub issue

What 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

  1. Build a page with some focusable elements
  2. Add a ComposedModal at the end of the page
  3. Show the modal and press Tab to move the focus.
  4. Observe that the focus is not trapped and actually follows through the browser URL bar and then the rest of the page.
  5. Move the modal to the start of the page and observe that the focus trap now works.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ptauntoncommented, Jul 25, 2019

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 the focusModal method in this case.

0reactions
asudohcommented, Jul 26, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found