Dialog
React Dialog components display a modal overlay above the main page content. They are commonly used to show information, ask a question, collect input from forms, or offer multiple actions that require the user's attention before continuing.
This Dialog component is built with React and styled using Tailwind CSS. It uses react-aria-components for accessibility, focus management, and keyboard interactions out of the box.
Installation
Install the component using the Tailgrids CLI.
npx @tailgrids/cli add dialogAnatomy
Import the component parts and combine them according to your requirements.
import {
Dialog,
DialogTrigger,
DialogOverlay,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogBody,
DialogFooter,
DialogClose
} from "@/registry/core/dialog";
export default function DialogAnatomy() {
return (
<Dialog>
<DialogTrigger />
<DialogOverlay>
<DialogContent>
<DialogHeader>
<DialogTitle />
<DialogDescription />
</DialogHeader>
<DialogBody />
<DialogFooter>
<DialogClose />
</DialogFooter>
</DialogContent>
</DialogOverlay>
</Dialog>
);
}Usage
Import the dialog components and compose them to build your modal.
import {
Dialog,
DialogTrigger,
DialogOverlay,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose
} from "@/registry/core/dialog";
export default function DialogExample() {
return (
<Dialog>
<DialogTrigger>Open Dialog</DialogTrigger>
<DialogOverlay isDismissable>
<DialogContent>
<DialogHeader>
<DialogTitle>Dialog Title</DialogTitle>
<DialogDescription>
A short description of the dialog purpose.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose>Cancel</DialogClose>
</DialogFooter>
</DialogContent>
</DialogOverlay>
</Dialog>
);
}Examples
Controlled Dialog
Advanced Statistics
To view your performance metrics and growth forecasts, you need to unlock Pro access.
Show Information
Display read-only information such as release notes, announcements, or details that the user needs to acknowledge.
Ask a Question
Use a confirmation dialog to ask the user a yes/no question before performing a destructive or irreversible action.
Collect Input
Present a form inside the dialog to collect user input such as profile settings, preferences, or text fields.
Multiple Actions
Offer the user multiple choices or actions to select from within a single dialog.
Without Close Button
You can remove the default close button at the top using showCloseButton={false} on DialogContent.
Sticky Footer
Keep the footer actions visible while the dialog content scrolls. Useful for long content like terms of service or license agreements.
Without Overlay
Render the dialog without a backdrop overlay by using DialogContent directly without wrapping it in DialogOverlay. This is useful for non-blocking notifications or confirmation screens where the background should remain visible.
API Reference
Dialog
The root component that manages the open/close state of the dialog.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | The trigger and content elements |
isOpen | boolean | - | Controlled open state |
defaultOpen | boolean | - | Uncontrolled default open state |
onOpenChange | (isOpen: boolean) => void | - | Called when the open state changes |
DialogTrigger
The button element that opens the dialog when pressed.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | The trigger label or element |
className | string | - | Additional CSS classes |
DialogOverlay
The backdrop overlay that covers the page behind the dialog. Wraps DialogContent and controls dismiss behavior.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | The DialogContent element |
isDismissable | boolean | true | Whether clicking outside the dialog closes it |
isKeyboardDismissDisabled | boolean | - | Whether pressing Escape to close is disabled |
className | string | - | Additional CSS classes for the overlay backdrop |
DialogContent
The main dialog panel. Composes Modal and Dialog from react-aria-components. Must be placed inside a DialogOverlay.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | (opts: { close: () => void }) => React.ReactNode | - | Content of the dialog. Supports render props for close() access |
showCloseButton | boolean | true | Whether to show the default close button in the top-right |
className | string | - | Additional CSS classes for the dialog panel |
DialogHeader
A semantic container for the title and description at the top of the dialog.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Header content |
className | string | - | Additional CSS classes |
DialogTitle
The dialog title. Uses react-aria's Heading with slot="title" for proper ARIA labelling.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Title text |
className | string | - | Additional CSS classes |
DialogDescription
A paragraph for supplementary text that describes the dialog's purpose.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Description text |
className | string | - | Additional CSS classes |
DialogBody
A scrollable content area between the header and footer.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Body content |
className | string | - | Additional CSS classes |
DialogFooter
An action bar at the bottom of the dialog for buttons and actions.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Footer content (buttons, links, etc.) |
showCloseButton | boolean | false | Whether to render a built-in "Close" button |
className | string | - | Additional CSS classes |
DialogClose
A button with slot="close" that automatically closes the nearest dialog when pressed. Can wrap any content for custom close triggers.
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | The close button label/content |
className | string | - | Additional CSS classes |
Accessibility
- Focus Management: Focus is automatically trapped inside the dialog when open and restored to the trigger on close.
- Keyboard Support: Press
Escapeto close the dialog (configurable viaisKeyboardDismissDisabledonDialogOverlay). - ARIA Labelling:
DialogTitleusesslot="title"to automatically setaria-labelledbyon the dialog. - Screen Readers: The dialog is announced as a modal overlay, and background content is hidden from assistive technology.
- Dismiss on Outside Click: Clicking the overlay backdrop closes the dialog when
isDismissableistrueonDialogOverlay. - Semantic HTML: Uses native
dialogsemantics via react-aria-components for maximum compatibility.