Components
Dialog
A focused interruption for a decision that needs the whole page to stop. Open, close and focus return are owned by the primitive.
A confirmation dialog should interrupt only the task that needs it. This preview scopes the overlay to the panel instead of the viewport.
Usage
A short decision that needs the rest of the page to stop.
Do and don't
- Do. Give it a title and keep one primary action in the footer.
- Don't. Use it for validation or nest a second modal without a reason.
Composition
Dialog owns the open state. DialogTrigger and DialogClose accept render or asChild so a Button can be the control. DialogContent holds DialogHeader, DialogTitle, DialogDescription and DialogFooter.
Props
Dialog:open,defaultOpen,onOpenChange,modal.DialogContent:size="sm" | "lg" | "xl",position="center" | "top",container,showCloseButton.DialogTrigger/DialogClose:render,asChild.
Behavior and states
The backdrop, Escape and outside press close the dialog; a controlled caller can react through onOpenChange. The exit spring is held until it finishes instead of being cut by unmount. Pass container with modal= to scope a dialog to a bounded region, as the preview above does. xl is the canvas for a composed layout with a sidebar beside a panel.
Accessibility
Give every dialog a DialogTitle; add DialogDescription when the purpose needs a sentence. Focus moves into the panel on open and returns to the trigger on close. Keep one primary action in the footer; a destructive action needs a clear, specific label and a route back. Do not nest a second modal without an explicit reason.
Responsive
sm is 400px, lg 540px and xl 880px, each one step narrower inside a compact region. For a bounded preview, pair container with a relatively positioned, overflow-hidden wrapper.
Related
States & Feedback defines when a condition should interrupt, and Motion & Transitions explains the open and close timing.