Skip to content
Browse docs and components

Dialog

dialog

A modal built on the Base UI primitive, so the focus trap, the inert background, Esc to close and the return of focus all come from one well tested place. The backdrop fades and the panel scales in, both in and out, and everything comes from the foundation tokens.

Responsive

Install

$npxshadcnadd@forme/dialog

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import {
  Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger,
} from "@/components/forme/dialog/dialog";

<Dialog>
  <DialogTrigger asChild>
    <Button variant="secondary">Rename workspace</Button>
  </DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Rename workspace</DialogTitle>
      <DialogDescription>Old links still resolve.</DialogDescription>
    </DialogHeader>
  </DialogContent>
</Dialog>

When to use

Reach for it

  • A task that has to be finished or dismissed before going on: a short form, a decision that needs context.

Use something else

  • A quick confirmation of something undoable — do it and offer Undo in a toast.
  • Long or multi-step flows that deserve their own page.
  • Panels on a phone that should come up from the bottom; use the Drawer.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

DialogTrigger

PropTypeDefaultDescription
asChildboolean—Render as the single child element instead of a <button>, keeping the open behaviour.

Also takes every prop of Base UI Dialog.Trigger.

DialogClose

PropTypeDefaultDescription
asChildboolean—Render as the single child element instead of a <button>, keeping the close behaviour.

Also takes every prop of Base UI Dialog.Close.

The other parts

  • DialogTakes Base UI Dialog.Root
  • DialogPortalTakes Base UI Dialog.Portal
  • DialogBackdropTakes Base UI Dialog.Backdrop
  • DialogContentTakes Base UI Dialog.Popup
  • DialogHeaderTakes <div> attributes
  • DialogFooterTakes <div> attributes
  • DialogTitleTakes Base UI Dialog.Title
  • DialogDescriptionTakes Base UI Dialog.Description

Accessibility

  • Base UI traps focus inside, makes the page behind it inert, closes on Esc and returns focus to the trigger.
  • DialogTitle and DialogDescription name and describe it for screen readers; keep both.

Motion

  • The scrim fades and the panel pops in on the standard duration, and both leave faster than they arrived.

Responsive behaviour

  • The panel is capped at max-w-md and the footer's buttons stack below sm.