StaffCoder
TypeScript
Vanilla TypeScriptTypeScript 7.0
6 modules · 24 challengesSign up
Module 2 · Events & Event Handling

Dismissible Dialog

easy0%0 of 1 solved

Problem statement

Wire dismissible-dialog behaviour onto a set of pre-existing DOM elements using Vanilla TypeScript and standard DOM APIs. The page already renders the dialog markup — an opener button, a dialog (backdrop), a panel, and a close button — your job is to attach the event handling that opens, closes, and manages focus.

Demo

The page, styles, and dialog markup are already scaffolded and wired. Only the initializeDialog function is missing — implement it in src/dismissibleDialog.ts so every test passes. Do not edit any other file.

What to implement

  • Open the dialog when the opener button is clicked, and move keyboard focus into the dialog.
  • Close the dialog when the close button is clicked, when the Escape key is pressed, or when the backdrop (the dialog itself) is clicked.
  • Keep the dialog open when a click lands inside the panel.
  • Return focus to the element that opened the dialog after closing.
  • Register the Escape key listener only while the dialog is open, and remove it on close so a later Escape press does nothing.
  • Do not use global variables or recreate any DOM elements — only the supplied elements are modified.

More in Events & Event Handling

See the module
Quantity StepperWire increment / decrement buttons to a numeric display bound between 1 and a supplied maximum, disabling each button at its bound. Values typed directly into the field are clamped on blur, and a change callback fires only when the value actually changes — not on repeat writes of the same number.0%0 of 1 solvedeasyLive Character CounterUpdate a counter on every input event showing characters used against a maximum, add a warning class within the last 20 chars, and block further input beyond the limit while still allowing deletion. Pasting an over-length string truncates to the limit. Use the input event, not keydown.0%0 of 1 solvedeasyFilter ToolbarWire a text input, a category select, and an in-stock checkbox so that changing any of them filters an in-memory array and re-renders the list under AND semantics — two active filters compose, not replace each other. Show a result count and a no-matches message; clearing a filter restores the previous set; the original array is never mutated.0%0 of 1 solvedeasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.