Dialog
Uncontrolled — defaultOpen initializes state; DialogTrigger and DialogClose flip it. No external props needed.
React
Svelte
Controlled mode
Section titled “Controlled mode”Parent owns open and onOpenChange (React) or uses bind:open (Svelte). Internal triggers fire onOpenChange instead of mutating internal state — the parent decides whether to honor the request.
Distant trigger
Section titled “Distant trigger”The trigger doesn’t have to be inside the dialog. Set data-dialog-open="{id}" on document.body from anywhere — a nav item, a keyboard shortcut, a server action. The dialog watches via MutationObserver.
React
Svelte
Dynamic content
Section titled “Dynamic content”Pre-fetch data, then flip open to true once it’s ready. The trigger shows a loading state while the promise resolves, then the dialog opens with content already rendered — all via the prop API.
Confirm dialog
Section titled “Confirm dialog”Confirm dialog
This will permanently remove checkout and all 14 connected effects.
import { Card, CardHeader, CardTitle, CardContent, CardFooter } from "@/components/ui/card"
import { Stack } from "@/components/ui/stack"
import { Field, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import { Checkbox } from "@/components/ui/checkbox"
import { Button } from "@/components/ui/button"
export function ConfirmDialog() {
return (
<Card className="max-w-sm">
<CardHeader><CardTitle>Delete state machine?</CardTitle></CardHeader>
<CardContent>
<Stack direction="col" gap="4">
<p className="text-sm text-muted-foreground">This will permanently remove checkout and all 14 connected effects.</p>
<Field>
<FieldLabel>Type 'checkout' to confirm</FieldLabel>
<Input placeholder="checkout" />
</Field>
<Field orientation="horizontal">
<Checkbox />
<FieldLabel>I understand this cannot be undone.</FieldLabel>
</Field>
</Stack>
</CardContent>
<CardFooter className="justify-end gap-2">
<Button variant="ghost">Cancel</Button>
<Button variant="destructive">Delete machine</Button>
</CardFooter>
</Card>
)
}