Focus Trap in Modals Playground

The delete-account modal on the neighbourhood head’s page: where does Bayu’s Tab go from the last button? A trap, a button added later, inert, showModal()…

Why it matters

Modals are everywhere: login, delete confirmations, forms. For mouse users a div and a dim backdrop look fine. For keyboard and screen reader users, with no trap they "Tab behind" the dialog; with a trap that has no door, they are locked in. Both bugs slip past QA because a mouse never shows them.

The key idea

Four jobs of a modal: hold focus, switch off the page behind, keep a door, give focus back

Common mistakes

Try it in this playground