Dialog
Web/MobileA modal window overlaid on the primary content for focused tasks, forms, and secondary flows.
Installation
pnpm dlx cubix-ui@latest add dialog --base ariaUsage
import { Button } from "@/components/cubix/button"
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/cubix/dialog"
<Dialog>
<DialogTrigger render={<Button variant="outline" size="sm" />}>نمایش دیالوگ</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>آیا کاملاً مطمئن هستید؟</DialogTitle>
<DialogDescription>
این کار قابل بازگشت نیست. حساب شما برای همیشه از سرورها حذف میشود.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose render={<Button variant="outline" size="sm" />}>انصراف</DialogClose>
<Button variant="destructive" size="sm">
حذف
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
Composition
Use the following composition to build a Dialog:
Dialog
├── DialogTrigger
└── DialogContent
├── DialogHeader
│ ├── DialogTitle
│ └── DialogDescription
├── …content
└── DialogFooter
├── DialogClose
└── ButtonExamples
With form
Compose Cubix TextField and EmailField inside the dialog when you need focused editing.
Without built-in close
Set showCloseButton={false} on DialogContent to hide the built-in X button and provide your own.
API Reference
Note: Dialog moves focus to its panel when it opens, traps focus, and dismisses on Escape or backdrop click. Prefer Alert Dialog when the user must confirm or cancel an irreversible action.
Dialog
The container that wraps the trigger and content and manages open state.
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | - | Controlled open state. Omit to use uncontrolled mode. |
| defaultOpen | boolean | false | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when the open state changes. |
| children | React.ReactNode | - | The trigger and content elements. |
DialogTrigger / DialogClose
The elements that open and close the dialog. Compose both with Cubix Button via render.
| Prop | Type | Default | Description |
|---|---|---|---|
| render | React.ReactElement | - | Render the trigger or close control as another Cubix element (e.g. a Button). |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
DialogContent
The modal panel rendered with a backdrop.
| Prop | Type | Default | Description |
|---|---|---|---|
| showCloseButton | boolean | true | Show the built-in close (X) button in the top end corner. |
| dir | "ltr" | "rtl" | "rtl" | Text direction of the portaled panel. Defaults to RTL for Persian-first layouts. |
| lang | string | "fa" | Language attribute applied when dir is "rtl". Pass dir="ltr" to omit it. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
DialogHeader / DialogFooter
Layout regions of the dialog content.
| Prop | Type | Default | Description |
|---|---|---|---|
| showCloseButton | boolean | false | Append a default outline Close button in the footer. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
DialogTitle / DialogDescription
The title and supporting text of the dialog.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |