InterviewDryRun
Frontend UI interview · Asked at junior and mid level

Build an accessible modal dialog

How the interviewer asks it

“Build a reusable modal dialog that opens from a button, has a title, a body and Confirm and Cancel buttons, and closes on Escape or a click on the backdrop. It must work for keyboard and screen reader users.”

Typed drills are free and unlimited: the AI scores your answer against the outline below.

What the interviewer is looking for

  • A clear component API: open state, onClose, title and children.
  • Correct semantics, ideally the native dialog element or role="dialog" with aria-modal and aria-labelledby.
  • Focus moves into the dialog, stays there while it is open and returns to the button afterwards.
  • Escape and backdrop clicks close it, and the page behind does not scroll.

How to structure your answer

  1. 01

    API

    A controlled component: open, onClose, title, children and the action buttons, rendered in a portal above the page.

  2. 02

    Semantics

    Use <dialog> with showModal(), which gives the backdrop, Escape and inert background for free; otherwise role="dialog", aria-modal="true" and a labelled title.

  3. 03

    Focus

    Focus the first sensible control on open, keep Tab inside the dialog, and give focus back to the trigger on close.

  4. 04

    Closing

    Escape and a click on the backdrop call onClose; clicks inside the panel do not.

  5. 05

    Layout

    Centred with a max width and max height, scrolling inside the body on small screens, and body scroll locked while open.

Best answers from candidates

No candidate answers yet. Type yours, and if it scores 6 or more you can show it here without your name.

Answers are shared by candidates, without names, after a privacy check. Add yours

Common mistakes

  • Forgetting to return focus to the button that opened the dialog.
  • Letting Tab wander into the page behind the overlay.
  • Closing the dialog when the user clicks inside it.

Follow-up questions to expect

  • Where should focus go when the dialog opens and when it closes, and how do you stop Tab from leaving it?
  • A second dialog opens from inside the first. What changes?

Now answer it out loud

Max will ask you this exact question, listen to your answer, push on the weak spots with follow-ups like the ones above, and score you when you finish.

Practice with Max

Free: a 5-minute voice round and unlimited typed drills, with scored feedback. No card, and your camera is never recorded.

More frontend UI interview questions