Skip to Content

Dialog

A modal dialog built on Base UI’s Dialog primitive. Includes a backdrop overlay, centered popup with scale/fade animation, title, and description.

Import

import { Dialog } from "chunks-ui";

Basic Usage

<Dialog.Root> <Dialog.Trigger>Open Dialog</Dialog.Trigger> <Dialog.Portal> <Dialog.Backdrop /> <Dialog.Popup> <Dialog.Title>Are you sure?</Dialog.Title> <Dialog.Description> This action cannot be undone. </Dialog.Description> <div className="mt-4 flex justify-end gap-2"> <Dialog.Close>Cancel</Dialog.Close> <Button color="destructive">Delete</Button> </div> </Dialog.Popup> </Dialog.Portal> </Dialog.Root>

With Backdrop

The Dialog.Backdrop renders a semi-transparent black overlay (bg-black/50) with a fade transition. It uses the z-overlays z-index layer:

<Dialog.Root> <Dialog.Trigger>Show</Dialog.Trigger> <Dialog.Portal> <Dialog.Backdrop /> <Dialog.Popup> <Dialog.Title>Dialog with backdrop</Dialog.Title> <Dialog.Description> The backdrop dims the content behind the dialog. </Dialog.Description> <Dialog.Close>Close</Dialog.Close> </Dialog.Popup> </Dialog.Portal> </Dialog.Root>

Controlled

function ControlledDialog() { const [open, setOpen] = useState(false); return ( <Dialog.Root open={open} onOpenChange={setOpen}> <Dialog.Trigger>Open</Dialog.Trigger> <Dialog.Portal> <Dialog.Backdrop /> <Dialog.Popup> <Dialog.Title>Controlled Dialog</Dialog.Title> <Dialog.Description>You can control the open state.</Dialog.Description> <Dialog.Close>Done</Dialog.Close> </Dialog.Popup> </Dialog.Portal> </Dialog.Root> ); }

Animation

The popup enters with a scale-up + fade transition (scale-95 to scale-100, opacity-0 to opacity-1) over 200ms. The backdrop fades in/out independently.

Compound Parts

PartDescription
Dialog.RootState container. Manages open/close.
Dialog.TriggerButton that opens the dialog.
Dialog.PortalRenders children in a portal outside the DOM tree.
Dialog.BackdropSemi-transparent overlay behind the dialog. z-overlays (500).
Dialog.PopupCentered content panel. z-modals (700). Max width max-w-md.
Dialog.TitleDialog heading. Rendered as a semibold text-lg.
Dialog.DescriptionSupporting text below the title. Rendered in text-muted-foreground.
Dialog.CloseButton that closes the dialog.

Dialog.Root Props

PropTypeDefaultDescription
openbooleanControlled open state
defaultOpenbooleanfalseInitial open state (uncontrolled)
onOpenChange(open: boolean) => voidCalled when open state changes
modalbooleantrueWhether the dialog is modal
Last updated on