{"success":true,"name":"make-modals-behave-escape-backdrop-focus-and-scroll","description":"Building a modal/dialog/popup, or an existing one traps or annoys users.","category":"ai-brimind","path":"ai-brimind/make-modals-behave-escape-backdrop-focus-and-scroll/SKILL.md","file":"SKILL.md","content":"---\nname: make-modals-behave-escape-backdrop-focus-and-scroll\ndescription: \"Building a modal/dialog/popup, or an existing one traps or annoys users.\"\n---\n\n# Make Modals Behave: Escape, Backdrop, Focus, and Scroll\n\n## When to use\nA modal or overlay dialog is being implemented, and closing behavior, background scroll, and focus handling are improvised.\n\n## Example request\nModal open, page behind still scrolls → the user scrolls, the backdrop shifts, orientation is lost — unlocked background. No Escape, no backdrop-click, tiny X only → users feel trapped hunting the exit — missing close conventions. Modal closes and focus vanishes to nowhere → keyboard users are lost; the next Tab starts from the page top — unmanaged focus lifecycle.\n\n## Instructions\nAct like a developer implementing a contract users already know — modals have conventions, and violating them feels broken. The checklist: (1) CLOSING — three ways, all working: Escape key, backdrop click (EXCEPT when the modal holds unsaved user input — then backdrop-click should not silently destroy work; confirm or ignore), and a visible close control; (2) SCROLL — lock the background page while open (overflow hidden on body, restored on close) so the world doesn't move under the dialog; the modal's own content scrolls internally if tall; (3) FOCUS lifecycle — on open, move focus into the modal (first field or the dialog itself); while open, Tab cycles INSIDE only (focus trap); on close, return focus to the element that opened it — this is what keeps keyboard and screen-reader users oriented; (4) SEMANTICS and stacking — role=dialog with a label, and rendered at body level (portal/append) so no parent stacking context or overflow clips it — ties into the z-index discipline; (5) check the platform first: the native <dialog> element and existing framework modal components implement most of this contract already — prefer them over rebuilding it. Only proceed once open → interact → close leaves scroll position, focus, and page state exactly as the user expects, verified by keyboard alone.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1193\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}