Dialog
Shows a focused task in a modal above the page.
dialog-demo.tsx
Installation
The CLI adds the files, packages, theme variables, and Tailwind plugin that this component uses. Before you run it, set up your project.
npm
yarn
pnpm
bun
Composition
DialogOwns the open state.
DialogTriggerDialogContentDialogHeaderDialogTitleDialogDescriptionOptionalDialogCloseOptionalCan also go in DialogFooter as a text button.
DialogBodyOptionalScrolls when the content does not fit.
DialogFooterOptional
Sizes
dialog-sizes-demo.tsx
Alert dialog
Set role="alertdialog" on DialogContent. An outside click nudges the dialog and does not close it.
dialog-alert-demo.tsx
Form
Put the form around DialogBody and DialogFooter, and call close after submit. Also install Form, Text field and Text area.
dialog-form-demo.tsx
Scrollable content
Only DialogBody scrolls. The header and footer stay in view.
dialog-scrollable-demo.tsx
Controlled open state
Escape and outside clicks also call onOpenChange.
dialog-controlled-demo.tsx
API reference
vip/ui adds or changes the props below. For all other props, see React Aria Modal (opens in a new tab).
DialogContent
- size: "sm" | "md" | "lg" | "xl" | "full" = "md"
- The maximum width from 640px up: 24rem, 28rem, 36rem, or 48rem. full fills the screen less a 1rem gutter. On phones, every size is full width, and full also fills the height.
- children: ReactNode | ({ close }) => ReactNodeRequired
- A function receives close, for example to close the dialog after a form submits.
- overlayProps: ModalOverlayProps = { isDismissable: true }
- React Aria ModalOverlay props, such as isDismissable and isKeyboardDismissDisabled. With role="alertdialog", outside clicks never close the dialog.
- modalProps: ModalProps
- Props for the panel. For a width that is not in size, set className here, for example sm:max-w-2xl.
DialogClose
Takes all Button props.
- children: ReactNode
- Text for the button. Without children, it shows an X icon labeled "Close dialog".
- variant: "default" | "secondary" | "outline" | "ghost" | "minimal" | "destructive" = "ghost"
- The Button variant.
- iconOnly: boolean
- Makes the button a square for one icon. The default is true without children and false with children.
- size: "xs" | "sm" | "md" | "lg" | "xl" = "sm" without children, "md" with children
- The Button size. An icon-only close button uses sm to stay compact.