Modals must contain focus
When a modal dialog is open, Tab should cycle within it instead of wandering to the hidden page behind.
Check that keyboard focus stays inside your modal or menu. Paste the component, tab through it in a sandbox and get a live log and verdict for escapes, wrap-around and Escape handling.
| Check | Result | Details |
|---|
Runs entirely in your browser. Nothing is uploaded to any server.
When a modal dialog is open, Tab should cycle within it instead of wandering to the hidden page behind.
Users must always be able to leave with Escape or a close button, or it becomes a WCAG 2.1.2 keyboard trap.
Focus can silently escape behind an overlay; a live log shows exactly where it goes.
Your code runs inside a sandboxed frame with scripts allowed but no access to this page, cookies or storage. A small listener is added to it that reports every focus change and every Tab, Shift+Tab and Escape key press back to the tester, along with whether the focused element is inside your container and whether the container is visible.
From that stream the tester decides whether focus ever left the container while it was open, whether pressing Tab on the last element wrapped to the first (and Shift+Tab the other way), whether Escape hid the container, and where focus went after it closed. Focus leaving the frame altogether, for example to the browser address bar, also counts as an escape.
Tab and Shift+Tab cycle only through the dialog's controls.
Escape closes the dialog without needing a mouse.
Closing returns focus to the button that opened the dialog.
Yes. The sandbox runs your scripts in an isolated, opaque origin that cannot read this page, your cookies or local storage.
The tester needs to see at least one full cycle through the container's focusable elements before it can confirm the trap.
A dialog opened with showModal() makes the rest of the page inert, so Tab stays inside the dialog and the browser chrome. Some browsers let focus move to the address bar, which this tester reports as leaving the sandbox.
WCAG 2.1.2 No Keyboard Trap fails when users cannot move focus away with the keyboard. A modal focus trap is fine as long as Escape or a close button lets users leave.
Elements that are hidden, disabled or have tabindex="-1" are excluded because they are not reachable with Tab.
More free tools from My Panda Toolbox.