Patch UI

Dialog

A modal dialog overlay with backdrop, header, content area, and footer. Built on Base UI's Dialog primitive with scroll locking and focus trapping.

$npx shadcn add @patchui/dialog

Basic

Without Close Button

Controlled (Destructive)

Usage

import {
  Button,
  Dialog,
  DialogTrigger,
  DialogContent,
  DialogHeader,
  DialogTitle,
  DialogDescription,
  DialogFooter,
  DialogClose,
} from "@patchui/react";
 
<Dialog>
  <DialogTrigger render={<Button />}>Open Dialog</DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Edit Profile</DialogTitle>
      <DialogDescription>
        Make changes to your profile here.
      </DialogDescription>
    </DialogHeader>
    <div className="p-6">
      {/* Content goes here */}
    </div>
    <DialogFooter>
      <DialogClose render={<Button variant="secondary" />}>
        Cancel
      </DialogClose>
      <DialogClose render={<Button />}>Save</DialogClose>
    </DialogFooter>
  </DialogContent>
</Dialog>

Props

DialogContent

PropTypeDefaultDescription
showCloseButtonbooleantrueWhether to render an X close button in the top-right corner.
classNamestring-Additional CSS classes applied to the dialog popup.

Compound Components

ComponentDescription
DialogRoot component managing open/close state. Accepts open and onOpenChange for controlled usage.
DialogTriggerRenders the element that opens the dialog. Use render prop for polymorphism.
DialogContentPortal-rendered popup with backdrop, scroll lock, and focus trap.
DialogHeaderFlex column container for title and description (padding included).
DialogTitleThe dialog's heading text.
DialogDescriptionSecondary description text below the title.
DialogPanelScrollable content area with padding.
DialogFooterFooter area for action buttons. Stacks vertically on mobile.
DialogCloseCloses the dialog when clicked. Use render prop to style as a Button.

Notes

  • Scroll locking: The dialog automatically prevents body scrolling while open via react-remove-scroll.
  • Focus trapping: Focus is trapped inside the dialog and returned to the trigger when closed.
  • Backdrop dismiss: Clicking the backdrop closes the dialog by default.
  • Polymorphic triggers: Use render={<Button />} on DialogTrigger and DialogClose to render them as styled buttons.
  • Controlled usage: Pass open and onOpenChange to Dialog to control visibility programmatically.