Challenge 3: Identify a Missing Modal Step — Possible Solution ==================================================================== THE SCENARIO ------------- A modal correctly (1) moves focus in on open and (2) traps focus while open, but on close, focus simply disappears — nothing is focused at all afterward. WHICH STEP IS MISSING ------------------------- STEP 3: Restore focus to whatever triggered the modal. The chapter is explicit that a correct modal does all THREE steps — move focus in, trap focus, and restore focus on close. This scenario has correctly implemented the first two but has skipped the third entirely: nothing captures which element originally opened the modal, and nothing calls .focus() on that element once the modal closes. THE USER IMPACT ------------------ When a keyboard user closes the modal (via an Escape key handler, a close button, or similar), their focus doesn't return to the button that opened the modal — it's simply "lost." In most browsers, this means the browser's focus resets to the very top of the document (often landing on the element itself, or nowhere in particular), rather than staying at the meaningful point in the page the user was actually working from. Concretely, this means a keyboard user who opened a modal from, say, the 15th item in a long list now has to tab all the way from the very top of the page back down to where they were, just to continue where they left off — a genuinely disorienting and frustrating experience, especially on a long or complex page. This is exactly the kind of "focus getting lost entirely and resetting to the top of the document" scenario the chapter's own modal section explicitly warns about as one of the two ways incomplete focus management goes wrong (the other being focus escaping into the hidden page behind the modal, which trapping — correctly implemented here — already prevents). THE FIX -------- Before moving focus INTO the modal (Step 1), capture a reference to whatever element currently has focus (document.activeElement) — this is, by definition, the element the user just interacted with to open the modal (the trigger button). Store that reference, and when the modal closes, explicitly call .focus() on it again — restoring the user's position exactly where they left off, rather than leaving focus to fall back to whatever the browser's default behavior happens to be in the absence of an explicit target.