Homework
Homework — an accessible dialog
Homework — an accessible dialog.
- Focus trap. Create
js/a11y.jswithtrapFocusandhideBackground. Use them inmodal.js'sopenModal/closeModal. - Test with the KEYBOARD. Open the modal, press
Tabmany times — focus should cycle inside, never leave to the background. Close withEsc— focus returns to the button that opened it. - Reproduce the bug. Comment out
trapFocus.Tabfrom the modal now goes to the nav behind it. Capture it (the focus ring is visible in the background). Restore it. - Background for screen readers. With
hideBackground, check (DevTools → Elements) that the otherbodychildren getaria-hidden="true"while the modal is open, and lose it on close. - Star keyboard.
makeRadioGroup— move with arrows, pick withSpace. Verify you can set a rating with no mouse. - Toasts + confirm. Add
toast.js(a transient message) andconfirm.js(a confirmation using the sametrapFocus).
Required tests:
- Trap test:
Tabcycles in the modal; withouttrapFocus— it escapes. - Restore test: on close, focus returns to the opening button.
- Keyboard test: you set the star rating with arrows.
To submit: a video (using ONLY the keyboard): (1) focus cycles in the modal, (2) it returns on close, (3) the stars via arrows; + a short note on why this is WCAG, not "polish".
Next. We have the whole UI — but it's still on one URL. In lesson 14 we build a router by hand: hash routes, deep links, a working Back button, and search synced into the URL. And you'll understand what a real router does for you.