Build · Components
A modal that respects focus

A modal that respects focus

Kathryn Gonzalez led design infrastructure at DoorDash, and in November 2017 she wrote How to Build a Modal: “While building a modal can seem simple from the start, there are a lot of cases and issues to discover once you release and iterate on it.” Three stories about one modal taught her team about z-index management, accessibility obligations, and a gap in testing.

Focus is on
nothing yet
Last 5 focus moves
  1. 1·
  2. 2·
  3. 3·
  4. 4·
  5. 5·
Adjust
save, focus first, keep within, restore
Figure 4. A focus trap, and the bug without one. Open the dialog with the trap on, then Tab and Shift+Tab: focus moves to the first field, cycles inside, and returns to the opener when you press Escape or Cancel, the four duties Kathryn Gonzalez lists. Turn the trap off, open again, and keep tabbing. Focus never enters on open and walks straight out of the dialog into the page behind it. The badges number the focusable elements, restarting inside the dialog, and the ring marks where focus is now.Illustrative numbers