What AuditX checks
The scan opens the page you scanned in a real browser and presses the Tab key forward, between 6 and 60 times (three presses per focusable element found), the same walk as the focus indicator check. After each press it reads which element has focus. It flags a possible trap when focus comes back to an element it already visited before it has reached the end of the page. Presses that only move inside one embedded frame, one video or audio player or one component that keeps focus inside itself are not counted as new stops, for up to 40 presses in a row. When a loop is found, the scan presses Escape, waits up to 1.5 seconds if the loop sits inside a dialog or a cookie notice, and then presses Tab again to see whether focus gets out. It passes when Tab never loops, when Escape or the next Tab gets out of the loop, or when the loop is a consent dialog whose answer buttons are part of the loop, because the visitor leaves it by answering. It gives an info note, which does not lower the score, when the loop is inside a dialog that has a close control but did not close on Escape, when the loop could not be fully confirmed or when the page has no focusable element. Any other loop is a fail, and the result says how many elements are in the loop. If the browser is not available, or the measurement fails even after one retry, the check is shown as not measured and is left out of the score. Only forward Tab is tested, on this one page, and the scan clicks and types nothing, so a trap that only appears after a menu or popup is opened is not found. On a page with more focusable elements than the press limit allows, only the first stops are tested.
Why it matters
A keyboard trap is a place where Tab moves focus around in a small loop and never lets the visitor reach the rest of the page. Someone who cannot use a mouse is stuck there.
WCAG success criterion 2.1.2, No Keyboard Trap, is a Level A requirement, the most basic level. It says that if focus can be moved into a component with the keyboard, it must also be possible to move it away again with the keyboard. Traps usually come from a script that handles keyboard events, such as a popup, a chat widget or a video player.
How to fix it
- Find the place where focus loops. The result tells you how many elements are in the loop. Tab through the page by hand to see where it happens.
- If it is a popup or dialog, make it close when Escape is pressed, give it a close button that can be reached with Tab, and move focus back to the button that opened it.
- If a script holds focus on purpose, change it so that it only does this while a dialog is open, and so that Tab can continue past the component otherwise.
- If a third-party widget causes it, such as a chat or cookie tool, look for a setting or an update, or ask the vendor.
Does your site pass this check? A free scan runs it with every other check and shows the result in about a minute.
Scan my siteSources
- W3C: Understanding Success Criterion 2.1.2 No Keyboard Trap
- W3C WAI-ARIA Authoring Practices: Modal Dialog pattern