Drawer
catnip-drawer opens as a native modal dialog. Focus moves in, stays inside, and returns to the trigger after close, and the page behind is inert. You provide the accessible name and, optionally, a description.
Keyboard
| Key | Behaviour |
|---|---|
| Tab / Shift + Tab | Moves between the drawer's controls; Tab stays within the modal. |
| Escape | Requests dismissal when closable is true. You close the drawer by updating open (see Controlled dismissal). While a tooltip inside the drawer is showing, the first Escape closes only the tooltip. |
- On open, focus moves into the drawer: an
autofocusdescendant when there is one, otherwise the first available action, with the drawer itself as the fallback. - Focus containment is native. A fallback Tab trap is used when native modal opening is unavailable.
- After closing, focus returns to the previously focused element.
- Backdrop dismissal remains opt-in.
Screen readers
- Opens with
showModal(), exposesrole="dialog"andaria-modal="true", and makes the page behind it inert. - Native dialog semantics announce the drawer's role, name, and optional description when focus enters. An
aria-liveregion is intentionally not added because it would duplicate that announcement. - The icon-only close button is named by
closeButtonAriaLabel(default "Close drawer").
What you own
- Accessible name: Every drawer needs one. Provide
drawerAriaLabelwhen the visible header cannot be referenced reliably across the custom element's shadow boundary. UseariaLabelledbywhen the referenced relationship is supported and verified in the consuming framework and browser matrix; it takes precedence overdrawerAriaLabel. - Description: Connect optional supporting text with
ariaDescribedbywhen appropriate. - Initial focus: Place
autofocuson the most useful initial control only when focusing it will not unexpectedly scroll past important introductory content. - Announcements: Do not add
aria-liveto the drawer: doing so can announce the same content twice. Use live regions inside the body only for genuinely dynamic status updates that occur after the drawer opens. - Stacked modals: If another modal must open over the drawer, ensure only the topmost modal accepts interaction and restore focus in the correct order.