components / overlay
Dialog
Modal window with managed focus that returns on close.
dialog-default.tsx
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogClose,
DialogDescription,
DialogFooter,
DialogHeader,
DialogPopup,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
export default function DialogDefault() {
return (
<Dialog>
<DialogTrigger render={<Button variant="outline" />}>delete project</DialogTrigger>
<DialogPopup closeLabel="Close">
<DialogHeader>
<DialogTitle>delete project?</DialogTitle>
<DialogDescription>this removes the project and all its files. this cannot be undone.</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose render={<Button variant="ghost" />}>cancel</DialogClose>
<DialogClose render={<Button variant="destructive" />}>delete</DialogClose>
</DialogFooter>
</DialogPopup>
</Dialog>
);
}Installation
$ npx shadcn@latest add https://cd-ui.vercel.app/r/dialog.jsonfirst time? set up components.json and the theme first: see installation.
Usage
import { Dialog, DialogPopup, DialogTitle, DialogTrigger } from "@/components/ui/dialog"
<Dialog>
<DialogTrigger render={<Button />}>open</DialogTrigger>
<DialogPopup>
<DialogTitle>title</DialogTitle>
</DialogPopup>
</Dialog>API
Dialog
Base UI · Dialog.RootRoot.
| prop | type | default |
|---|---|---|
open · defaultOpen · onOpenChangeOpen state control. | boolean / (open) => void | - |
DialogTrigger · DialogClose
Base UI · Dialog.Trigger · Dialog.CloseOpen and close. Use render to use your own Button.
| prop | type | default |
|---|---|---|
renderSwaps the rendered element while keeping behavior and style (e.g. become an | ReactElement | (props) => ReactElement | - |
DialogPopup
Base UI · Dialog.PopupCentered window with a dimmed backdrop. Enters with a scale (160ms), leaves faster (120ms).
| prop | type | default |
|---|---|---|
showCloseShows the X in the corner. | boolean | true |
closeLabelLabel of the X for screen readers. | string | "Close" |
positionWhere the window sits: centered, or anchored near the top (command palettes). | "center" | "top" | "center" |
instantOpens and closes without animation. Use it for dialogs opened by a keyboard shortcut. | boolean | false |
classNameExtra classes, merged with | string | - |
DialogHeader · DialogTitle · DialogDescription · DialogFooter
Content structure. Title and description are announced when it opens.
| prop | type | default |
|---|---|---|
classNameExtra classes, merged with | string | - |
Keyboard
| key | action |
|---|---|
| Esc | Closes and returns focus to the trigger. |
| Tab | Cycles only inside the window. |