Modal
Focused tasks and confirmations that block the page until resolved.
Playground
The panel follows the controls in place; the button opens the same dialog for real, with focus trap, overlay and Esc. Use a modal only when the task must be finished or dismissed before going on.
Invite to Northwind portal
Teammates get edit access. You can change their role later.
Props
1import { Button } from "@/components/ui/button"2import {3 Dialog,4 DialogClose,5 DialogContent,6 DialogDescription,7 DialogFooter,8 DialogHeader,9 DialogTitle,10 DialogTrigger,11} from "@/components/ui/dialog"12import { Input } from "@/components/ui/input"13import { Label } from "@/components/ui/label"1415<Dialog>16 <DialogTrigger asChild>17 <Button variant="outline">Invite people</Button>18 </DialogTrigger>19 <DialogContent className="sm:max-w-md">20 <DialogHeader>21 <DialogTitle>Invite to Northwind portal</DialogTitle>22 <DialogDescription>Teammates get edit access. You can change their role later.</DialogDescription>23 </DialogHeader>24 <div className="grid gap-1.5">25 <Label htmlFor="invite-email">Email address</Label>26 <Input id="invite-email" type="email" placeholder="name@company.com" />27 </div>28 <DialogFooter>29 <DialogClose asChild>30 <Button variant="outline">Cancel</Button>31 </DialogClose>32 <Button>Send invite</Button>33 </DialogFooter>34 </DialogContent>35</Dialog>States
The trigger has the usual button states. The panel has its own: at rest, submitting (inputs and Cancel lock, Esc is ignored), a validation error that keeps the dialog open, and done.
- Default
rest - Hover
:hover - Focus
:focus-visible - Loading
aria-busy - Disabled
disabled - Error
aria-invalid - Success
data-state=success
Rename project
Teammates see the new name right away.
Rename project
Teammates see the new name right away.
Rename project
Teammates see the new name right away.
Use at least 3 characters.
Project renamed
Northwind portal is now “Northwind portal v2”.
Examples
A destructive confirmation, a form that validates and shows progress before closing, and long content with a fixed header and footer.
Northwind portal
24 files, updated today
Not accepted yet.
Submit empty to see validation, then fill it in.
Keyboard
- Next focusable, wraps inside the dialog
- Tab
- Previous focusable
- Shift+Tab
- Close and return focus to the trigger
- Esc
- Submit the form
- Enter
Semantics and ARIA
- Content is a
dialogwitharia-modal, named byDialogTitlethrougharia-labelledbyand described byDialogDescriptionthrougharia-describedby. - Focus is trapped while open and the rest of the page is hidden from assistive tech. On close, focus returns to the element that opened it.
- Destructive confirmations use
role="alertdialog", have no corner X and put Cancel first so it receives initial focus. - On submit errors, focus moves to the first invalid field, which has
aria-invalidand a message that says how to fix it. - Scrollable bodies are focusable regions with a name, so keyboard users can scroll them with the arrow keys.
- Don’t stack dialogs. If a step needs more room, move it to a page or a sheet.