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/aria/dialog.jsonnpx shadcn@latest add https://kit.dev/r/aria/dialog.jsonpnpm dlx shadcn@latest add https://kit.dev/r/aria/dialog.jsonyarn shadcn@latest add https://kit.dev/r/aria/dialog.jsonThis component depends on Button. Install it first if you haven't already.
Install the following dependencies:
bun add react-aria-components tailwind-variants lucide-reactnpm install react-aria-components tailwind-variants lucide-reactpnpm add react-aria-components tailwind-variants lucide-reactyarn add react-aria-components tailwind-variants lucide-reactCopy and paste the following code into your project.
"use client";
import { XIcon } from "lucide-react";
import type React from "react";
import {
Dialog as DialogPrimitive,
DialogTrigger as DialogTriggerPrimitive,
type DialogTriggerProps,
Heading,
Modal,
ModalOverlay,
type ModalOverlayProps,
} from "react-aria-components";
import { tv, type VariantProps } from "tailwind-variants";
import { cn } from "@/lib/utils";
import { Button, type ButtonProps } from "@/registry/aria/components/button";
import {
usePreviewFrame,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
childrenReact.ReactNodeAttributeType
DialogTrigger
PropType
childrenReactNodeclassName?stringAttributeType
DialogClose
PropType
childrenReact.ReactNodeclassName?stringAttributeType
DialogOverlay
PropType
childrenReact.ReactNodeAttributeType
DialogHeader
PropType
childrenReact.ReactNodeAttributeType
DialogTitle
PropType
childrenReact.ReactNodeAttributeType
DialogDescription
PropType
childrenReact.ReactNodeAttributeType
DialogFooter
PropType
childrenReact.ReactNodeAttributeType