Dialog
A wrapper around the native <dialog> element. The library does not reimplement focus trapping, Escape handling, top-layer stacking or background inerting: the browser already does all of that for a modal opened with showModal().
Example (a11y tier)
Import
import Dialog from 'abaabil/dialog' // structure onlyimport Dialog from 'abaabil/dialog/styled' // + CSSimport Dialog from 'abaabil/dialog/a11y' // + open/close, labeling, light dismissWhat the a11y tier adds, and what it deliberately doesn't
- Calls
showModal()/close()on the underlying<dialog>in response to theopenprop. - Sets an accessible name from
label, and renders it as a visible title. Warns in development iflabelis omitted. - Light dismiss: a mousedown that lands on the dialog element itself (not its children, which is what a click on the native backdrop area looks like) closes it.
- Does not implement a focus trap. That is deliberate:
dialog.showModal()natively provides focus containment, Escape dismissal,aria-modal="true", top-layer rendering and an inert background. Reimplementing that in JavaScript is most of why other libraries' dialogs are far larger than this one.
Props
| Prop | Type | Default | Tier | Description |
|---|---|---|---|---|
className | string | — | all | Merged with the base class. |
open | boolean | false | a11y | Drives showModal() / close(). |
onClose | function | — | a11y | Called on the native close event (Escape, form method=dialog, light dismiss, or a programmatic close). |
label | string | — | a11y | Accessible name. The platform does not supply one; also rendered as a visible title. |
ref | ref | — | a11y | Composes with the component's own ref to the <dialog> element. |
onMouseDown | function | — | a11y | Composes with the component's own light-dismiss handler. |
| ...props | — | — | all | Everything else spreads onto the <dialog> element. |