UI.MD

Dialog

A modal dialog overlay with customizable header, content, and footer.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/dialog.json

Usage

import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, DialogClose } from "@/components/ui/dialog"

Examples

Default

A form dialog. DialogFooter showCancelButton adds a Cancel that closes the dialog, placed left of your primary action. initialFocus focuses the first field with the caret at the end instead of selecting its text.

Scrollable

Long content scrolls in a ScrollFade region while the header and footer stay put. gap-0 lets the dividers own their spacing, and every band around one is the dialog's own 24px padding. The max-height goes on the viewport, not the root.

Share

A utility dialog: read-only field with an in-field copy button (Input actionEnd) and a Done action. initialFocus moves focus to the copy button instead of auto-selecting the URL.

API Reference

PropTypeDefaultDescription
openDialogboolean-Controlled open state. Pair with onOpenChange.
onOpenChangeDialog(open: boolean) => void-Called when the open state changes.
defaultOpenDialogbooleanfalseUncontrolled initial open state.
modalDialogbooleantrueWhen true, blocks interaction with the rest of the page and traps focus.
showCloseButtonDialogContentbooleantrueShows the X close button in the top-right corner.
showCancelButtonDialogFooterbooleanfalseAdds a ghost Cancel button that closes the dialog, placed left of your actions.
initialFocusDialogContentboolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | HTMLElement | null | void)trueThe element to focus when the dialog opens. Pass a ref to focus a specific element, or a function returning an element, true for default behavior, or false/null/void to leave focus alone.
renderDialogTrigger, DialogCloseReact.ReactElement-Replaces the default trigger or close button with your own element, e.g. render={<Button>Done</Button>}. Base UI merges props onto it.