Dialog
A modal window that interrupts the flow for a decision or a short task, and requires a response before returning.
Select the button to open the dialog. Press Escape or use the footer to close it.
When to use
- To confirm an action that is hard to undo.
- To collect a few fields without leaving the current page.
- To stop the flow when something needs an answer before it can continue, such as an expiring session.
When not to use
- Long forms or multi-step tasks. Use a Drawer or a Sheet, or a page.
- Messages that need no answer. Use an Alert or a toast.
- Help text for a control. Use a Tooltip or a Popover.
- Anything the user may want to read while working elsewhere. A modal blocks the page.
Anatomy
A dialog is built from parts. Always include a title and a way out.
| Part | Role |
|---|---|
Dialog |
Holds the open state. |
DialogTrigger |
The element that opens it. Use asChild with a Button. |
DialogContent |
The panel and its dark backdrop. Adds the corner × unless hidden. |
DialogHeader |
Groups the title and the description. |
DialogTitle |
Names the dialog. Required for assistive technology. |
DialogDescription |
One or two sentences of context. |
DialogFooter |
The actions. Supporting action first, main action last. |
DialogClose |
Closes the dialog. Use asChild on the cancel button. |
Examples
Confirm a decision
State what will happen and who is affected. Name the action on the button.
Destructive confirmation
Use the critical variant on the confirm button and say what will be lost.
Short form
Without the corner button
Content
- Write the title as the question or the result: “Excluir a tarefa?”, not “Atenção”.
- The description adds consequences, not repetition of the title.
- Buttons name the action: “Excluir tarefa”, “Enviar para revisão”. Avoid “Sim” and “OK”.
- Put the main action on the right, the cancel action on its left.
Do and don’t
Accessibility
- Built on Radix Dialog: focus moves into the dialog on open, stays inside it, and returns to the trigger on close.
Escapecloses the dialog and the page behind it cannot be reached.DialogTitlenames the dialog andDialogDescriptiondescribes it, so both are read when it opens. Never leave them out.- The corner × is labelled “Close”. Pass translated copy with
closeLabel. - If you use
hideCloseButton, the footer must always offer a way to close.
Code
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@repo/ui/dialog";
import { Button } from "@repo/ui/button";
<Dialog>
<DialogTrigger asChild>
<Button variant="secondary">Revisar contestação</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Enviar contestação para revisão?</DialogTitle>
<DialogDescription>O revisor recebe o documento agora.</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose asChild>
<Button variant="secondary">Cancelar</Button>
</DialogClose>
<Button variant="primary">Enviar para revisão</Button>
</DialogFooter>
</DialogContent>
</Dialog>;
Props
Dialog| Prop | Type | Default | Description |
|---|---|---|---|
defaultOpen | boolean | false | Initial open state when the dialog is uncontrolled |
modal | boolean | true | Blocks interaction with the rest of the page while open |
onOpenChange | (open: boolean) => void | — | Called when the dialog opens or closes |
open | boolean | — | Controlled open state |
DialogContent| Prop | Type | Default | Description |
|---|---|---|---|
hideCloseButton | boolean | false | Hides the corner × button. |
closeLabel | string | "Close" | Accessible name of the corner button. Pass translated copy from the app. |
overlayClassName | string | — | Extra class for the backdrop. |
DialogTrigger, DialogClose| Prop | Type | Default | Description |
|---|---|---|---|
asChild | boolean | false | Renders the child element instead of a button, for DialogTrigger and DialogClose. |
Known issues
| Issue | Effect |
|---|---|
The backdrop is bg-black/80, a translucent fill. |
The repository avoids transparency in UI. A solid token or a blur-free overlay is not available yet. |
| The corner × has no padding: its hit target is 16px. | Below the 24px minimum. Harder to hit with a mouse and on touch screens. |
DialogTitle and DialogDescription use raw classes instead of Typography. |
The text styles do not follow the type scale tokens. |
The close button uses ring-offset-background and bg-accent. |
Depends on tokens from the old color system. |