Dialog
Built on the native dialog element and showModal(), so the browser makes the rest of the page inert and puts the dialog in the top layer. Prism adds what the browser cannot: the panel and backdrop spring both ways, and Escape is routed through the spring. Focus moves to data-autofocus and returns to the invoker. The alertdialog role drops the close button and ignores backdrop presses for confirmations.
- <dialog>
- showModal()
- inert
- Spring Physics
- Scroll lock
The page behind becomes inert, not just covered. Open the visibility menu inside the dialog and press Escape: the menu closes first, then the dialog. Focus comes back to the button that opened it.
Usage
Drop it in
import { Dialog } from "@/app/lib/components/dialog";<Dialog
open={open}
onOpenChange={setOpen}
role="alertdialog"
title="Delete this project?"
description="Its 12 files go with it. This cannot be undone."
footer={<>
<button data-autofocus onClick={() => setOpen(false)}>Cancel</button>
<button onClick={remove}>Delete</button>
</>}
/>API
Props
| Prop | Type | Default |
|---|---|---|
open*Whether it is open. | boolean | — |
onOpenChange*Called with false when it asks to close: Escape, the close button, or a press on the backdrop. | (open: boolean, reason: DismissReason) => void | — |
title*Names the dialog. Rendered as its heading. | string | — |
descriptionDescribes it, linked with aria-describedby. | ReactNode | — |
children | ReactNode | — |
footerButtons along the bottom. Put `data-autofocus` on the one that should take focus first. | ReactNode | — |
role"alertdialog" for confirmations that need an answer: a backdrop press does not dismiss it, and there is no close button. Default: "dialog" | "dialog" | "alertdialog" | "dialog" |
sizePanel width. Default: "md" | "sm" | "md" | "lg" | "md" |
className | string | "" |
Read from the component's source at build time. * required.
Accessibility
Works with
- Cursor
- Reacts to where the pointer is, not just whether it's over the element.
- Touch
- Follows your finger while it's down, then settles a moment after you lift.
- Keyboard
- Focus lights it up the way the cursor does. Every action has a key.
- Reduced motion
- Nothing moves or springs. Colour still answers, without drifting.