Dialog

Modal interruptions on the native <dialog>: focus stays inside, Escape closes it and the page behind is inert.

Renders

dialog

Intents

Domains

Examples

Confirming a decision

You keep open in state. Escape, a click outside and the Cancel button all close it.

Preview
function Confirm() {
const [asking, setAsking] = useState(false);
const deleteProject = () => setAsking(false);
return (
<>
<Action intent="action.delete" onClick={() => setAsking(true)}>Delete project</Action>
<Dialog intent="dialog.confirm" open={asking} onClose={() => setAsking(false)} label="Delete this project?">
<Layout intent="layout.section">
<Text intent="heading.item" as="h2">Delete this project?</Text>
<Text intent="text.body">The project and all its data will be gone for good.</Text>
<Layout intent="layout.actions">
<Action intent="action.cancel" onClick={() => setAsking(false)}>Cancel</Action>
<Action intent="action.delete" onClick={deleteProject}>Delete</Action>
</Layout>
</Layout>
</Dialog>
</>
);
}

Intents it renders

One domain, with its own page of neighbours and examples. The intent decides the element; these are the starter intents.

Dialog dialog.*

5 intents
  • dialog.task

    A focused task that blocks the page until done or dismissed: edit settings, compose

    <dialog>
  • dialog.confirm

    Asks the user to confirm or cancel one decision

    <dialog>
  • dialog.media

    Shows one photo or video large over the dimmed page, with its details beside it: who posted it, the caption, comments. A click outside closes it. On small screens it fills the screen, the photo between its title and its details

    <dialog>
  • dialog.reader

    Shows one piece of content over the whole screen: reading an article

    <dialog>
  • dialog.drawer

    A full-height panel that slides in from the side over the dimmed page: site navigation on a small screen. A click outside closes it

    <dialog>

Props

Plus its element’s usual attributes (id, onClick, aria-*, data-*). No className or style.

  • intent required
  • open required

    Whether it is showing. You keep it in state.

    boolean
  • onClose required

    Called on Escape, a click outside, or when it closes itself.

    () => void
  • label required

    The accessible name: usually the heading text.

    string
  • children required

    The content. It renders only while the dialog is open.

    ReactNode
  • unsafeClassName

    Bypasses the intent. Needs a // prongs-unsafe: <reason> comment on the line above, and prongs check counts it.

    string

Rules

  • Put a heading, the content and a layout.actions row inside.

  • Keep open in state and set it to false in onClose.