View fulldotdev/ui on GitHub

Dialog

A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.

Installation

npx shadcn@latest add @fulldev/dialog

Usage

import {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
<Dialog>
  <DialogTrigger>Open</DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Are you absolutely sure?</DialogTitle>
      <DialogDescription>
        This action cannot be undone. This will permanently delete your account
        and remove your data from our servers.
      </DialogDescription>
    </DialogHeader>
  </DialogContent>
</Dialog>

DialogTrigger and DialogClose render a Button and take its props, such as variant="outline". DialogContent moves to document.body while open, so a form around the whole dialog does not contain the content: put the form inside DialogContent when the dialog submits.

Composition

Dialog
├── DialogTrigger
└── DialogContent
    ├── DialogHeader
    │   ├── DialogTitle
    │   └── DialogDescription
    └── DialogFooter

Custom Close Button

Replace the default close control with your own DialogClose.

No Close Button

Use showCloseButton={false} to hide the close button.

Keep actions visible while the content scrolls.

Scrollable Content

Long content can scroll while the header stays in view.

RTL

API Reference

Source: src/components/ui/dialog

Dialog propTypeDefault
defaultOpenbooleanfalse
closeOnClickOutsidebooleantrue
closeOnEscapebooleantrue
lockScrollbooleantrue
alertDialogbooleanfalse
DialogContent propTypeDefault
showCloseButtonbooleantrue

Open or close a dialog from a script with root.dispatchEvent(new CustomEvent("dialog:set", { detail: { open: true } })) and listen for dialog:change. See the Data Slot docs for all events and data attributes.