Frontend live coding · 30 minutes
Accessible modal dialog
Build a modal dialog component in React in 30 minutes. Start from an empty file and use no UI library. A button opens the dialog. The dialog has a title, some content, and a Close and a Confirm button. It must behave as a real dialog for mouse, keyboard and screen reader users. You may use the native dialog element or build the dialog from a div; say which one you choose and why. Explain your decisions while you code, as in a live round.
Requirements
- A button opens the dialog; the Close button, the Escape key and a click on the backdrop close it
- It is exposed as a modal dialog: the native dialog element opened with showModal, or role dialog with aria-modal set to true
- It has an accessible name: aria-labelledby points to the title
- When it opens, focus moves into the dialog, and Tab and Shift+Tab cannot reach the page behind
- When it closes, focus returns to the button that opened it
- The page behind does not scroll and cannot be used while the dialog is open
- The component API is small: open, onClose, title and children
What reviewers look for
What reviewers look for, the checklist and the stretch goals opens with a year in the app. What a year includes