How do you find and fix a keyboard trap?

A keyboard trap occurs when focus enters a component and the user cannot move out with standard keyboard commands. Test every interactive area with Tab, Shift+Tab, arrow keys and Escape without using a pointer. Embedded media, custom widgets, editors, menus and modal dialogs are common places to find traps.
Begin before the suspected component, tab into it and try to continue in both directions. Record the focused element and key that fails. Distinguish an intentional modal focus loop from a trap: a modal may contain focus while open, but it must provide an operable close action, usually support Escape, and return focus sensibly after closing.
Common causes include:
- JavaScript preventing default key behavior without an exit path;
- focus repeatedly sent back to the same control;
- an invisible overlay intercepting keystrokes;
- iframes or plugins that do not release focus;
- roving tabindex code with no route back to the page;
- a close button that is unreachable or unlabeled.
Fix the component’s keyboard model rather than adding arbitrary timeout or blur logic. Let Tab leave ordinary widgets, implement correct wrapping only inside active modals, and make Escape behavior predictable. If a technology requires an unusual exit command, provide clear instructions before the user enters it, though standard behavior is strongly preferable.
Retest from both directions with the supported browsers and assistive technologies, including error and loading states. Confirm that focus remains visible after escape and reaches the next logical element. A component is not trap-free merely because a developer knows a secret key combination; the exit must be discoverable and operable by the intended user.