DialogTitleDialogDescriptionDialogClosemodaldisablePointerDismissalimport { Button } from "@/components/ui/button"
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"
export function EditProfile() {
return (
<Dialog>
<DialogTrigger render={<Button />}>Open Dialog</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>
Make changes to your profile here. Click save when you're done.
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<label htmlFor="name" className="text-sm font-medium">Name</label>
<input id="name" defaultValue="John Doe" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm" />
</div>
<div className="space-y-2">
<label htmlFor="username" className="text-sm font-medium">Username</label>
<input id="username" defaultValue="@johndoe" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm" />
</div>
</div>
<DialogFooter>
<DialogClose>Cancel</DialogClose>
<Button>Save changes</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}Usage
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
export function RenameProject() {
return (
<Dialog>
<DialogTrigger render={<Button />}>Rename project</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Rename project</DialogTitle>
<DialogDescription>The new name shows everywhere at once.</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose>Cancel</DialogClose>
<Button>Save</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}Examples
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose,
DialogTrigger,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
export function Example() {
return (
<Dialog>
<DialogTrigger render={<Button />}>Open Dialog</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit Profile</DialogTitle>
<DialogDescription>
Make changes to your profile here. Click save when you're done.
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<label htmlFor="name" className="text-sm font-medium">Name</label>
<input id="name" defaultValue="John Doe" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm" />
</div>
<div className="space-y-2">
<label htmlFor="username" className="text-sm font-medium">Username</label>
<input id="username" defaultValue="@johndoe" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm" />
</div>
</div>
<DialogFooter>
<DialogClose>Cancel</DialogClose>
<Button>Save changes</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}import React from 'react';
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose,
DialogTrigger,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
export function Example() {
const [open, setOpen] = React.useState(false);
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger render={<Button variant="destructive" />}>Delete Item</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Confirm Deletion</DialogTitle>
<DialogDescription>
Are you sure you want to delete this item? This action cannot be undone.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose>Cancel</DialogClose>
<Button variant="destructive" onClick={() => setOpen(false)}>
Delete
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose,
DialogTrigger,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
export function Example() {
return (
<Dialog>
<DialogTrigger render={<Button />}>Edit Settings</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Account Settings</DialogTitle>
<DialogDescription>
Manage your account preferences.
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<label htmlFor="display-name" className="text-sm font-medium">Display name</label>
<Input id="display-name" defaultValue="John Doe" />
</div>
<div className="space-y-2">
<label htmlFor="email" className="text-sm font-medium">Email</label>
<Input id="email" defaultValue="john@example.com" />
</div>
</div>
<DialogFooter>
<Dialog>
<DialogTrigger render={<Button variant="destructive" />}>
Delete Account
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you absolutely sure?</DialogTitle>
<DialogDescription>
This will permanently delete your account and all associated data. This action cannot be undone.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose>Go Back</DialogClose>
<Button variant="destructive">Yes, Delete</Button>
</DialogFooter>
</DialogContent>
</Dialog>
<DialogClose>Cancel</DialogClose>
<Button>Save Changes</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}import React from 'react';
import {
Dialog, DialogContent, DialogHeader, DialogTitle,
DialogDescription, DialogFooter, DialogClose, DialogTrigger,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Radio, RadioGroup } from '@/components/ui/radio';
import { Checkbox } from '@/components/ui/checkbox';
export function Example() {
const [severity, setSeverity] = React.useState("medium");
return (
<Dialog>
<DialogTrigger render={<Button />}>Create Rule</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Create Monitoring Rule</DialogTitle>
<DialogDescription>
Configure a rule to trigger notifications for important events.
</DialogDescription>
</DialogHeader>
<div className="space-y-5 py-4">
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<label htmlFor="rule-name" className="text-sm font-medium uppercase tracking-wide">Name</label>
<Input id="rule-name" placeholder="Ex: NVDA" />
</div>
<div className="space-y-2">
<label className="text-sm font-medium uppercase tracking-wide">Condition</label>
<Select defaultValue="volatility">
<SelectTrigger>
<SelectValue />
</SelectTrigger>
{/* portal={false} keeps the dropdown inside the dialog focus trap */}
<SelectContent portal={false}>
<SelectItem value="price-above">Price above</SelectItem>
<SelectItem value="price-below">Price below</SelectItem>
<SelectItem value="volatility">Volatility</SelectItem>
<SelectItem value="volume-spike">Volume spike</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="space-y-2">
<label className="text-sm font-medium uppercase tracking-wide">Severity</label>
<RadioGroup value={severity} onValueChange={(value) => setSeverity(value as string)} className="grid grid-cols-3 gap-3">
{["low", "medium", "high"].map((value) => (
<label
key={value}
className="flex cursor-pointer items-center gap-2 rounded-md border border-input px-3 py-2.5 text-sm has-checked:border-primary has-checked:bg-primary/5"
>
<Radio value={value} />
<span className="capitalize">{value}</span>
</label>
))}
</RadioGroup>
</div>
<div className="space-y-2">
<label className="text-sm font-medium uppercase tracking-wide">Notify via</label>
<div className="grid grid-cols-3 gap-3">
{[{ label: "Slack", defaultChecked: true }, { label: "Email", defaultChecked: true }, { label: "SMS", defaultChecked: false }].map((ch) => (
<label
key={ch.label}
className="flex cursor-pointer items-center gap-2 rounded-md border border-input px-3 py-2.5 text-sm has-checked:border-primary has-checked:bg-primary/5"
>
<Checkbox defaultChecked={ch.defaultChecked} />
<span>{ch.label}</span>
</label>
))}
</div>
</div>
<div className="space-y-2">
<label htmlFor="rule-notes" className="text-sm font-medium uppercase tracking-wide">Notes</label>
<Textarea id="rule-notes" placeholder="Alert context, owner, and escalation path..." rows={3} />
</div>
</div>
<DialogFooter>
<DialogClose>Cancel</DialogClose>
<Button>Save Rule</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}Notes
Composing the layers
DialogContent is DialogPortal, DialogBackdrop, DialogViewport and DialogPopup stacked in that order. Compose them yourself to style or drop a layer; the agent still finds the popup.
Popups inside a dialog
A Select inside a dialog renders its list in place by default, so it stays inside the dialog's focus trap and stacking. The With form example composes Input, Select, Radio, Checkbox and Textarea this way.
API
details.cancel() refuses it.trap-focus only traps focus.Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
Agent
Inside an AgentProvider, it appears in agent.snapshot() as dialog.
Reads
labelThe DialogTitle while open. The trigger's name while closed, or while open with no title.
openWhether the dialog is showing. Open dialogs are listed first.
Actions
open()While closed. act returns the opened dialog under appeared.
close()While open.
An agent's open or close runs through onOpenChange. isAgentChange(details) is true for it; details.cancel() refuses it and tells the agent. Controls inside report the dialog's title as in.
await agent.act({
steps: [{ ref: "Open Dialog", action: "open" }],
})Accessibility
- The popup is a dialog named by
DialogTitleand described byDialogDescription. - Give every dialog a
DialogTitle; the agent reads the same name. - While modal, focus is trapped and the page behind is inert.
- Focus returns to the trigger on close, unless
finalFocussays otherwise. - Reduced motion turns the animation into a fade.