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/base/dialog.jsonnpx shadcn@latest add https://kit.dev/r/base/dialog.jsonpnpm dlx shadcn@latest add https://kit.dev/r/base/dialog.jsonyarn shadcn@latest add https://kit.dev/r/base/dialog.jsonThis component depends on Button. Install it first if you haven't already.
Install the following dependencies:
bun add @base-ui/react tailwind-variants lucide-reactnpm install @base-ui/react tailwind-variants lucide-reactpnpm add @base-ui/react tailwind-variants lucide-reactyarn add @base-ui/react tailwind-variants lucide-reactCopy and paste the following code into your project.
"use client";
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
import { XIcon } from "lucide-react";
import type React from "react";
import { tv, type VariantProps } from "tailwind-variants";
import { cn } from "@/lib/utils";
import { Button } from "@/registry/base/components/button";
import {
usePreviewFrame,
usePreviewPortal,
} from "@/registry/react/lib/preview-frame";
export const Dialog = (props: DialogPrimitive.Root.Props) => (
<DialogPrimitive.Root data-slot="dialog" {...props} />
);
export const DialogTrigger = (props: DialogPrimitive.Trigger.Props) => (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
AttributeType
DialogTrigger
button
PropType
AttributeType
DialogOverlay
div
PropType
AttributeType
DialogTitle
h2
PropType
AttributeType
DialogDescription
p
PropType
AttributeType
DialogPortal
div
PropType
AttributeType
DialogClose
button
PropType
AttributeType
DialogContent
PropType
AttributeType
DialogHeader
PropType
AttributeType
DialogFooter
PropType
AttributeType