shadcn.io is not affiliated with official shadcn/ui
Shadcn Dialog for React
A modal window that appears on top of the main content.
Installation
bunx --bun shadcn@latest add https://kit.dev/r/radix/dialog.jsonnpx shadcn@latest add https://kit.dev/r/radix/dialog.jsonpnpm dlx shadcn@latest add https://kit.dev/r/radix/dialog.jsonyarn shadcn@latest add https://kit.dev/r/radix/dialog.jsonThis component depends on Button. Install it first if you haven't already.
Install the following dependencies:
bun add radix-ui tailwind-variants lucide-reactnpm install radix-ui tailwind-variants lucide-reactpnpm add radix-ui tailwind-variants lucide-reactyarn add radix-ui tailwind-variants lucide-reactCopy and paste the following code into your project.
"use client";
import { XIcon } from "lucide-react";
import { Dialog as DialogPrimitive } from "radix-ui";
import type React from "react";
import { tv, type VariantProps } from "tailwind-variants";
import { cn } from "@/lib/utils";
import { Button } from "@/registry/radix/components/button";
import {
usePreviewFrame,
usePreviewPortal,
} from "@/registry/react/lib/preview-frame";
export const Dialog = (
props: React.ComponentProps<typeof DialogPrimitive.Root>
) => <DialogPrimitive.Root data-slot="dialog" {...props} />;
export const DialogTrigger = (Update the import paths to match your project setup.
Anatomy
DialogTrigger
DialogOverlay
DialogPositioner
DialogContent
DialogTitle
DialogDescription
DialogCloseUsage
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import {
Field,
FieldGroup,
FieldLabel,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";<Dialog>
<form>
<DialogTrigger asChild>
<Button variant="outline">Open Dialog</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-sm">
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>
Make changes to your profile here. Click save when you're done.
</DialogDescription>
</DialogHeader>
<FieldGroup>
<Field>
<FieldLabel>Name</FieldLabel>
<Input defaultValue="Pedro Duarte" name="name" type="text" />
</Field>
<Field>
<FieldLabel>Username</FieldLabel>
<Input defaultValue="@peduarte" name="username" type="text" />
</Field>
</FieldGroup>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
<Button type="submit">Save changes</Button>
</DialogFooter>
</DialogContent>
</form>
</Dialog>Accessibility
| Key | Description |
|---|---|
Enter | Activate the focused control. |
Space | Activate the focused control. |
Demos
Close Button
Replace the default close control with your own button.
No Close Button
Use showCloseButton={false} to hide the close button.
Sticky Footer
Keep actions visible while the content scrolls.
Scrollable Content
Long content can scroll while the header stays in view.
Rtl
Right-to-left dialog. See the RTL configuration guide for document direction.
API Reference
Dialog
PropType
openboolean): voidchildren?React.ReactNodedefaultOpen?booleanmodal?booleanAttributeType
DialogTrigger
button
PropType
openboolean): voidchildren?React.ReactNodedefaultOpen?booleanmodal?booleanAttributeType
DialogTitle
h2
PropType
openboolean): voidchildren?React.ReactNodedefaultOpen?booleanmodal?booleanAttributeType
DialogDescription
div
PropType
openboolean): voidchildren?React.ReactNodedefaultOpen?booleanmodal?booleanAttributeType
DialogPortal
PropType
openboolean): voidchildren?React.ReactNodedefaultOpen?booleanmodal?booleanAttributeType
DialogClose
PropType
openboolean): voidchildren?React.ReactNodedefaultOpen?booleanmodal?booleanAttributeType
DialogOverlay
PropType
openboolean): voidchildren?React.ReactNodedefaultOpen?booleanmodal?booleanAttributeType
DialogContent
PropType
openboolean): voidchildren?React.ReactNodedefaultOpen?booleanmodal?booleanAttributeType
DialogHeader
PropType
openboolean): voidchildren?React.ReactNodedefaultOpen?booleanmodal?booleanAttributeType
DialogFooter
PropType
openboolean): voidchildren?React.ReactNodedefaultOpen?booleanmodal?booleanAttributeType