Skip to content

Dialog

Modal dialog on Radix Dialog: a titled panel with body and footer slots, focus trapping, Escape and backdrop dismiss, and entry/exit animation.

// Radix — @radix-ui/react-dialog
import { CloseButton, Dialog, DialogClose } from "@shavin/ui";

Opened from a trigger

Pass trigger and Dialog keeps its own open state. Wrap a footer button in DialogClose to close from it.

Component Source
import { Dialog, DialogClose, Button } from "@shavin/ui";

<Dialog
  trigger={<Button>Download statement</Button>}
  title="Download October statement"
  description="All four accounts, as a PDF."
  footer={
    <>
      <DialogClose asChild>
        <Button variant="ghost">Cancel</Button>
      </DialogClose>
      <DialogClose asChild>
        <Button>Download</Button>
      </DialogClose>
    </>
  }
/>

Controlled, with a form

Hold open yourself when something else opens or closes the dialog, or when you need to close it after saving. The body takes any content.

Current name: Groceries

Component Source
const [open, setOpen] = useState(false);
const [name, setName] = useState("Groceries");

<Button variant="outline" onClick={() => setOpen(true)}>Rename budget</Button>
<Dialog
  open={open}
  onOpenChange={setOpen}
  size="md"
  title="Rename budget"
  footer={
    <>
      <Button variant="ghost" onClick={() => setOpen(false)}>Cancel</Button>
      <Button type="submit" form="rename-budget">Save</Button>
    </>
  }
>
  <form id="rename-budget" onSubmit={(e) => { e.preventDefault(); save(name); setOpen(false); }}>
    <TextField label="Budget name" value={name} onChange={(e) => setName(e.target.value)} />
  </form>
</Dialog>

Sizes

Maximum widths: sm 384px (default), md 448px, lg 672px. On narrow screens the dialog fills the width less 16px each side.

Component Source
<Dialog size="sm" … />
<Dialog size="md" … />
<Dialog size="lg" … />

Layouts

layout="centered" drops the header row and centres the text, for confirmations and success moments. layout="bare" keeps the title above the content with a corner close button, for forms that lead with their fields. Both are undivided unless you pass divided.

Component Source
<Dialog
  layout="centered"
  trigger={<Button variant="outline">Centered</Button>}
  title="Budget saved"
  description="Groceries resets to $600 on December 1."
  footerAlign="stretch"
  footer={<DialogClose asChild><Button>Done</Button></DialogClose>}
>
  <Icon name="CircleCheck" size="lg" color="success" />
</Dialog>

<Dialog
  layout="bare"
  trigger={<Button variant="outline">Bare</Button>}
  title="Add a bill"
  footer={<DialogClose asChild><Button>Add bill</Button></DialogClose>}
>
  <TextField label="Payee" placeholder="City Water & Power" />
</Dialog>

Backdrop clicks ignored

dismissible={false} stops a click outside from closing the dialog, so a half-filled form is not lost. Escape and the close button still work.

Component Source
<Dialog
  open={open}
  onOpenChange={setOpen}
  dismissible={false}
  title="Import transactions"
  footer={<Button onClick={() => setOpen(false)}>Close</Button>}
>
  Clicking outside does not close this dialog.
</Dialog>

Dialog or AlertDialog

Use Dialog for tasks people can walk away from: forms, details, pickers. To ask for a decision before something destructive or irreversible, such as deleting an account, use AlertDialog, which needs an explicit answer. For a panel that slides in from the edge, use Drawer.

Accessibility

title is the dialog's accessible name and description its description, so keep the title short and specific. Focus moves into the dialog when it opens, stays inside while it is open, and returns to the trigger when it closes. The close button is labelled "Close".

Keyboard

KeyAction
TabMoves to the next focusable element inside the dialog.
Shift + TabMoves to the previous focusable element inside the dialog.
EscapeCloses the dialog and returns focus to the trigger.

Data attributes

AttributeValues
[data-state]"open" | "closed" on the overlay and the content while mounted.

Props

PropTypeDefaultDescription
title*ReactNode—Heading shown at the top of the dialog (also its accessible name).
descriptionReactNode—Supporting line under the title (also its accessible description).
openboolean—Controlled open state. Pair with `onOpenChange`.
defaultOpenboolean—Initial open state when uncontrolled. Default: closed when `trigger` is set, otherwise open.
onOpenChange(open: boolean) => void—Called whenever the dialog asks to open or close (trigger, Escape, backdrop, close button).
triggerReactNode—Element that opens the dialog, e.g. `<Button>Edit profile</Button>`.
onClose() => void—Called after the close animation finishes. Use it to unmount a dialog you render conditionally.
childrenReactNode—Dialog body.
footerReactNode—Footer actions, right-aligned. Wrap a button in `<DialogClose asChild>` to close from it.
dismissiblebooleantrueWhether clicking the backdrop closes the dialog. Default true.
layout"default" | "centered" | "bare"—Header treatment. `default`: left-aligned title row with a close button. `centered`: centred title and description, no header row (for confirmations, success and invite moments). `bare`: no header row; the title and description sit above the content with no chrome (for forms and pickers that lead with their content).
dividedboolean—Hairlines between header, body and footer. Default: on for `default`, off for `centered` and `bare`.
footerAlign"start" | "center" | "end" | "between" | "stretch"`end`Footer button alignment. `stretch` makes buttons share the row (good on mobile). Default `end`.
size"sm" | "md" | "lg""sm"—

* required

Configure Theme
Theme
Brand Color
Custom
Gray Family
Appearance
Radius
Scaling
Panel Style
Heading Font
Body Font