Dialog

Web/Mobile

A modal window overlaid on the primary content for focused tasks, forms, and secondary flows.

Installation

pnpm dlx cubix-ui@latest add dialog --base radix

Usage

Import
import { Button } from "@/components/cubix/button"
import {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/cubix/dialog"
Example
<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
        └── Button

Examples

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.

PropTypeDefaultDescription
openboolean-Controlled open state. Omit to use uncontrolled mode.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange(open: boolean) => void-Called when the open state changes.
childrenReact.ReactNode-The trigger and content elements.

DialogTrigger / DialogClose

The elements that open and close the dialog. Compose both with Cubix Button via render.

PropTypeDefaultDescription
renderReact.ReactElement-Render the trigger or close control as another Cubix element (e.g. a Button).
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

DialogContent

The modal panel rendered with a backdrop.

PropTypeDefaultDescription
showCloseButtonbooleantrueShow 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.
langstring"fa"Language attribute applied when dir is "rtl". Pass dir="ltr" to omit it.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

DialogHeader / DialogFooter

Layout regions of the dialog content.

PropTypeDefaultDescription
showCloseButtonbooleanfalseAppend a default outline Close button in the footer.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

DialogTitle / DialogDescription

The title and supporting text of the dialog.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).