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 bounded region (custom scrollbar) while the header and footer stay fixed. gap-0 on the content keeps both dividers on a symmetric 16px (py-4 above, pb-4 / pt-4 below).

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.