DLG-007 Keep Tab inside a modal dialog and the page behind it out of use
- Level
- Rule
- Verdict
- Unanimous (2 of 2)
- Area
- Dialogs
- Status
- proposed, version 1.0.0
Rule
While a modal dialog is open, Tab and Shift+Tab stay within it, and nothing behind it can be used until it closes.
Examples
Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.
Do: Tab goes round inside the dialog
This week
- Nothing planned
- Nothing planned
- Nothing planned
Don't: Tab walks on into the page behind
This week
- Nothing planned
- Nothing planned
- Nothing planned
Why
A modal dialog says: answer this first. A sighted mouse user gets that message from the dimmed page. A keyboard user gets it only if Tab stays in the dialog. If Tab walks on into the page behind, focus disappears under the dialog or its backdrop, and the person may change something they cannot see while the question is still waiting. No WCAG criterion requires a modal dialog to hold focus, so the judges decide this rule. The law permits it and is easier to meet with it. Holding focus is not a trap under WCAG 2.2, 2.1.2 No Keyboard Trap as long as the dialog can be closed from the keyboard, which DLG-001 and KBD-001 see to. Focus that never goes behind the dialog cannot be hidden by it, which helps meet 2.4.11 Focus Not Obscured (Minimum), and a focus order that stops at the dialog's edge supports 2.4.3 Focus Order. What a dialog tells assistive technology about itself should be true, as 4.1.2 Name, Role, Value asks of every state, and a dialog announced as modal is only truthful when the page behind is out of use, so the rule supports that criterion too. How focus gets in and where it goes afterwards is DLG-006.
Do
- In a meal planner, the dialog Plan a meal has a close icon, Day, Recipe, Servings, Cancel and Add to plan. Tab on Add to plan goes to the close icon, the first control in the dialog. Shift+Tab on the close icon goes to Add to plan.
- Behind the dialog, the week's grid, the shopping list and the navigation cannot be clicked, tapped or tabbed to until the dialog closes.
- Keep a screen reader in the dialog too. Its own reading keys do not use Tab, so a Tab loop alone does not stop it from wandering into the week's grid. This is our own technical point, and it supports 4.1.2: what is announced as modal should be modal.
- Our own choice of technique: make the page behind inert, with the
inertattribute or with the nativedialogelement opened withshowModal()(see H102), rather than rely on a script that catches Tab. Inert stops the keyboard, the pointer and assistive technology in one step. - Mark the dialog as modal in code, with
aria-modal="true"or the native element, only when the page behind really is out of use. - Hold focus only in a dialog that can be closed from the keyboard. Escape does what Cancel does, as DLG-001 says, and Cancel is always there in a form, as FRM-003 says.
- The list of recipes under Recipe and the calendar under Day belong to the dialog, even if the code draws them elsewhere in the page. Focus may move into them and comes back to their control.
- The browser's own controls, such as the address bar, are not the page behind. With the native
dialogelement Tab may pass through them before it returns to the dialog, and that is fine. - When one short confirmation sits over a full-screen dialog, as DLG-002 allows, the full-screen dialog counts as the page behind for as long as the confirmation is open.
- A press on the backdrop either takes the dismissive path in DLG-001 or does nothing. It never reaches a control underneath. In the adapter's
AlertDialogthe press does nothing, and focus stays where it was in the dialog. InDialogthe press closes the dialog, and focus goes back to the opener as DLG-006 says. If something holds the close, such as a discard question, the dialog stays open and focus stays where it was in it. Keeping focus in place on a press that does not close is our own choice. - The adapter's
DialogandAlertDialogare modal: Radix, which they are built on, keeps Tab inside, and the content is markedaria-modal="true". A dialog opened over another makes the one beneath inert. Do not passmodal={false}toDialog: it turns the hold off while the content is still marked as modal. Check in your own build, with a screen reader, that nothing behind the dialog is read.
Don't
- Let Tab leave Plan a meal after Add to plan and move through the week's grid behind the backdrop.
- Dim the page but leave its links open to a click, or the other way round: block the pointer and let Tab through.
- Catch Tab in a script and stop there, so a screen reader still reads the page behind and can press its buttons.
- Set
aria-modal="true"on a panel that people are meant to work beside. - Hold focus in a dialog that has no way out from the keyboard. That is the trap 2.1.2 forbids.
- Hold the keyboard in a layer that still lets the pointer use the page, and call it non-modal. Choose one: modal and closed off, or non-modal and free. An overlay panel that keeps focus inside until it is closed, as KBD-002 allows, counts as modal here, so the page behind it is out of use too.
Exceptions
- While sending. Between the press on the main action and the reply, STA-005a may make Cancel, Escape and the close icon unavailable. That wait ends with the reply or with a failure the person can act on, so the dialog is not one without a way out.
- Non-modal panels, toasts and tooltips. A panel people work beside, a toast or a tooltip never holds focus. LAY-002 covers how the keyboard reaches a panel, and KBD-002 what a layer may cover.
- A busy layer. Content under a loading layer is made unreachable in the same way, but that moment belongs to STA-001.
- Neighbouring rules. Moving focus in and back is DLG-006. Leaving the dialog by keyboard is DLG-001 and KBD-001. One dialog at a time is DLG-002.
Verdict
Unanimous (2 of 2). Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work
| Source | Role | Stance | Page |
|---|---|---|---|
| WCAG 2.2 | Law | Supports | 2.1.2 No Keyboard Trap |
| WCAG 2.2 | Law | Supports | 2.4.11 Focus Not Obscured (Minimum) |
| WCAG 2.2 | Law | Supports | 2.4.3 Focus Order |
| WCAG 2.2 | Law | Supports | 4.1.2 Name, Role, Value |
| Material Design | Judge | Supports | Dialogs: accessibility Dialogs: guidelines |
| Apple Human Interface Guidelines | Judge | No position | |
| Carbon Design System | Judge | Supports | Dialogs Modal: usage Modal: accessibility |
| GOV.UK Design System | Expert witness | No position | |
| Nielsen Norman Group | Expert witness | No position |
Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.
History
- Version 1.0.0, : First version.
Last checked against the other rules for conflicts on .
More in Dialogs: 5 rules and 2 guidelines · All rules
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.