ComponentCompound

Dialog

A modal dialog with compound components for trigger, overlay, content, and actions. Uses the headless @refraction-ui/dialog core.

Live Example

Click a button to open a dialog. Press Escape or click the overlay to close.

Installation

$pnpm add @refraction-ui/react-dialog

Usage

tsx
import {
  Dialog,
  DialogTrigger,
  DialogOverlay,
  DialogContent,
  DialogHeader,
  DialogTitle,
  DialogDescription,
  DialogFooter,
  DialogClose,
  Button,
} from '@refraction-ui/react'

export function MyDialog() {
  return (
    <Dialog>
      <DialogTrigger asChild>
        <Button>Open Dialog</Button>
      </DialogTrigger>
      <DialogOverlay>
        <DialogContent>
          <DialogHeader>
            <DialogTitle>Are you sure?</DialogTitle>
            <DialogDescription>
              This action cannot be undone.
            </DialogDescription>
          </DialogHeader>
          <DialogFooter>
            <DialogClose asChild>
              <Button variant="outline">Cancel</Button>
            </DialogClose>
            <Button>Confirm</Button>
          </DialogFooter>
        </DialogContent>
      </DialogOverlay>
    </Dialog>
  )
}

Dialog Props

PropTypeDefaultDescription
openboolean--Controlled open state.
defaultOpenbooleanfalseInitial open state for uncontrolled usage.
onOpenChange(open: boolean) => void--Callback when open state changes.
modalbooleantrueWhether the dialog behaves as a modal.

Compound Components

PropTypeDefaultDescription
DialogTriggerButtonHTMLAttributes--Button that toggles the dialog open/closed.
DialogOverlayHTMLAttributes<HTMLDivElement>--Backdrop overlay that closes dialog on click.
DialogContentHTMLAttributes<HTMLDivElement>--The dialog content panel. Handles Escape key.
DialogHeaderHTMLAttributes<HTMLDivElement>--Header section with flex column layout.
DialogTitleHTMLAttributes<HTMLHeadingElement>--Dialog title (h2) linked via aria-labelledby.
DialogDescriptionHTMLAttributes<HTMLParagraphElement>--Dialog description linked via aria-describedby.
DialogFooterHTMLAttributes<HTMLDivElement>--Footer section with action buttons layout.
DialogCloseButtonHTMLAttributes--Button that closes the dialog.