2.1.2 No Keyboard Trap: If keyboard focus can be moved to a component of the page using a keyboard interface, then focus can be moved away from that component using only a keyboard interface, and, if it requires more than unmodified arrow or tab keys or other standard exit methods, the user is advised of the method for moving focus away. (Level A)
- No item traps the keyboard focus. Upon reaching any item on the page, it is possible to move to the item that precedes or follows it using the keyboard.
Why is it important?
This ensures that people who use a keyboard do not get stuck on any part of the page.
Make sure that keyboard-only users don’t get trapped within any element. When someone using a keyboard to navigate content moves to an element, they must be able to move away from it again.
A modal dialogue opens but cannot be closed with the keyboard, preventing the user from accessing the original content underneath;
Content is presented in an infinite scroll, so a keyboard user is forced to tab through everything before they can exit the scroll area.
- On your designs, indicate the order in which interactive elements should receive keyboard focus.
- Also indicate when actioning a button should move the keyboard focus somewhere else. This will help make sure that components such as dialogs can be closed easily by users.
Example: Designing a modal dialog for the Web
- Opening a modal dialog should move the keyboard focus to an element inside the modal dialog, rather than keeping the keyboard focus outside it. It’s best to move the keyboard focus to the ‘Close’ button inside the modal dialog, or to the main header within the dialog.
- The keyboard focus should stay within the modal dialog when users press the ‘Tab’ key several time, rather than go back to content behind the modal dialog.
- There should be a button to close or dismiss the modal dialog. Pressing that button should return the keyboard focus to the button that triggered modal dialog in the first place (so that the user go back to where they were on the page before opening the modal dialog).
No Keyboard Trap Examples for Web
- Do not embed elements that may trap focus.
- Modal dialog example in the ARIA Authoring Practices Guide
- W3C’s detailed explanation with techniques and examples.
- Keyboard accessibility article by WebAIM
- Accessibility Guidelines- Github.io