liveBook · Manning

Modal dialog

As explained in Architecting Accessibility

A modal dialog is an interface dialog that temporarily makes underlying page content unavailable until the dialog is dismissed.

A modal dialog temporarily makes the page behind it unavailable. For keyboard users, clear focus movement helps signal the change and prevents them from getting lost. section 5.3

Manage keyboard focus throughout the dialog’s lifecycle:

  • When it opens, move focus inside. For a simple confirmation, focus an interactive element; for a dialog with important information, focus its heading or container. section 5.3.2
  • While it remains open, keep focus within it so Tab and Shift+Tab do not reach background content. section 5.3.2
  • When it closes, return focus to the element that opened it. If that element no longer exists, move focus to the next logical place on the page. section 5.3.2

Choose the starting point

For a disclaimer dialog containing important information, place initial focus on the heading rather than assuming the first action is the best starting point. section 5.3.2

<h2 id=”modal_title” tabindex=”-1”>Disclaimer</h2> 

A heading can be made programmatically focusable as the dialog’s initial focus target. section 5.3.2

document.getElementById(“modal_title”).focus()

Set focus to the heading with JavaScript when the dialog opens. section 5.3.2

How Architecting Accessibility covers it

How deep it goes
Specifies focus entry, containment, dismissal, and return behavior, but does not provide a complete focus-trapping implementation.
Examples
Uses a transaction confirmation, a disclaimer heading, and Esc or dialog buttons to illustrate focus handling.
What you can do after
Operate keyboard focus by moving it into the dialog, containing it while open, and restoring it after dismissal.
How it connects
Connects modal dialogs to keyboard navigation, focus order, and JavaScript focus management.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Architecting Accessibility. The section links point to the parts of the book it draws on.