HomeChallengesRepsProblemsLeaderboardTake a challenge

The modal that traps focus

A dialog that looks right and cannot be operated. Announce it as a dialog, take focus when it opens, keep Tab inside it, hand focus back when it closes, and let Escape out.

Intermediate20 min on the clock6 graded checks · 100 pointsReachable by Everyone

AssumesModal DialogYou have already built this modal. Its checklist scored how it looked — this one scores whether it can be operated.

Graded by reading your code against the checklist below.

What you build

  • role="dialog" and aria-modal="true" on the panel
  • aria-labelledby pointing at the heading that names it
  • Escape closes the dialog
  • Focus moves into the panel when it opens
  • Tab and Shift+Tab wrap inside the panel
  • Focus returns to whatever opened it

Done means

Openable, operable and escapable without a mouse, and focus is never left behind the overlay.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else.

  1. The panel announces itself as a modal dialog+20Accessibility
  2. The dialog has an accessible name+15Accessibility
  3. Escape closes it+20Accessibility
  4. Focus moves into the panel when it opens+20Accessibility
  5. Tab and Shift+Tab wrap inside the panel+15Accessibility
  6. Focus returns to whatever opened it+10Accessibility

What it teaches

The rest of Reachable by Everyone