Appearance
Dialog
The Dialog component provides a modal dialog with a compound component API. It is backed by Base UI's Dialog primitive.
Import
tsx
import { Dialog } from "@tailor-platform/app-shell";Basic Usage
tsx
function BasicUsage() {
return (
<Dialog.Root>
<Dialog.Trigger render={<Button />}>Open</Dialog.Trigger>
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Confirm Action</Dialog.Title>
<Dialog.Description>Are you sure you want to proceed?</Dialog.Description>
</Dialog.Header>
<Dialog.Footer>
<Dialog.Close render={<Button variant="outline" />}>Cancel</Dialog.Close>
<Button>Confirm</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
);
}Sub-components
| Sub-component | Description |
|---|---|
Dialog.Root | Manages open/close state |
Dialog.Trigger | Element that opens the dialog when clicked |
Dialog.Content | The main dialog panel (includes overlay and close button automatically) |
Dialog.Header | Layout wrapper for title and description |
Dialog.Footer | Layout wrapper for action buttons |
Dialog.Title | Dialog title (announced by screen readers) |
Dialog.Description | Additional context below the title |
Dialog.Close | Button that closes the dialog |
Props
Dialog.Root Props
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | - | Controlled open state |
defaultOpen | boolean | false | Initial open state (uncontrolled) |
onOpenChange | (open: boolean) => void | - | Callback when open state changes |
modal | boolean | true | Whether the dialog is modal |
children | React.ReactNode | - | Dialog sub-components |
Dialog.Content Props
Accepts className and all standard HTML <div> props.
Tall Content
Dialog.Content is never taller than the viewport minus 2rem (16px above and below, the same margin as on the sides). When the content is taller, the whole dialog scrolls, including the title and the close button. Escape and a click on the backdrop still close it.
On open, focus moves to the first control in the dialog. In a dialog that scrolls, this happens only when that control is in view at the top. When it is below the fold (for example, a footer button after a long body), the dialog itself takes focus instead, so it opens at the top rather than scrolled to that control. Tab then moves to the control. Pass initialFocus to choose the element yourself.
To keep a header or footer in view while only the body scrolls, make Dialog.Content a flex column and give the body min-h-0 flex-1 overflow-y-auto. A className with its own max-h-* or overflow-* replaces the defaults.
Dialog.Trigger / Dialog.Close Props
Accept a render prop for custom element rendering (Base UI render pattern), plus standard button props.
Controlled Usage
tsx
function Controlled() {
const [open, setOpen] = useState(false);
return (
<>
<Button variant="outline" onClick={() => setOpen(true)}>
Open Dialog
</Button>
<Dialog.Root open={open} onOpenChange={setOpen}>
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Settings</Dialog.Title>
</Dialog.Header>
<Dialog.Footer>
<Button onClick={() => setOpen(false)}>Done</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
</>
);
}Examples
Delete Confirmation
tsx
function DeleteConfirmation({ onDelete }: { onDelete: () => void }) {
return (
<Dialog.Root>
<Dialog.Trigger render={<Button variant="destructive" />}>Delete</Dialog.Trigger>
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Delete Order</Dialog.Title>
<Dialog.Description>
This action cannot be undone. The order will be permanently deleted.
</Dialog.Description>
</Dialog.Header>
<Dialog.Footer>
<Dialog.Close render={<Button variant="outline" />}>Cancel</Dialog.Close>
<Button variant="destructive" onClick={onDelete}>
Delete
</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
);
}Form Dialog
tsx
function EditDialog({ item }: { item: Item }) {
const [name, setName] = useState(item.name);
return (
<Dialog.Root>
<Dialog.Trigger render={<Button variant="outline" />}>Edit</Dialog.Trigger>
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Edit Item</Dialog.Title>
</Dialog.Header>
<Input value={name} onChange={(e) => setName(e.target.value)} />
<Dialog.Footer>
<Dialog.Close render={<Button variant="outline" />}>Cancel</Dialog.Close>
<Button onClick={() => handleSave(name)}>Save</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
);
}Accessibility
- Dialog title is announced by screen readers via
Dialog.Title - Focus is trapped inside the dialog while open
- Pressing
Escapecloses the dialog - The close button is always present inside
Dialog.Content