Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Marker
- Message
- Message Scroller
- Native Select
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Trace
- Typography
AI Elements
Get Started
@shadcn/react
@shadcn/helpers
Utilities
import { Button } from "@/components/ui/button"
import {
Dialog,import { Button } from "@/components/ui/button"
import {
Dialog,
DialogClose,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Field, FieldGroup } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export function DialogDemo() {
return (
<DialogTrigger>
<form>
<Button variant="outline">Open Dialog</Button>
<Dialog 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>
<Label htmlFor="name-1">Name</Label>
<Input id="name-1" name="name" defaultValue="Pedro Duarte" />
</Field>
<Field>
<Label htmlFor="username-1">Username</Label>
<Input id="username-1" name="username" defaultValue="@peduarte" />
</Field>
</FieldGroup>
<DialogFooter>
<DialogClose variant="outline">Cancel</DialogClose>
<Button type="submit">Save changes</Button>
</DialogFooter>
</Dialog>
</form>
</DialogTrigger>
)
}
Installation#
pnpm dlx shadcn@latest add dialog
Install the following dependencies:
pnpm add react-aria-components
Copy and paste the following code into your project.
"use client"
import * as React from "react"
import { cn } from "cn"
import { XIcon } from "lucide-react"
import {
Dialog as DialogPrimitive,
DialogTrigger as DialogTriggerPrimitive,
Heading,
ModalOverlay as ModalOverlayPrimitive,
Modal as ModalPrimitive,
type DialogProps as DialogPrimitiveProps,
type DialogTriggerProps as DialogTriggerPrimitiveProps,
type ModalOverlayProps as ModalOverlayPrimitiveProps,
} from "react-aria-components"
import { Button } from "@/components/ui/button"
function DialogTrigger({ ...props }: DialogTriggerPrimitiveProps) {
return <DialogTriggerPrimitive data-slot="dialog-trigger" {...props} />
}
function DialogClose({
className,
variant = "outline",
size = "default",
...props
}: React.ComponentProps<typeof Button>) {
return (
<Button
slot="close"
data-slot="dialog-close"
variant={variant}
size={size}
className={cn(className)}
{...props}
/>
)
}
function DialogOverlay({
className,
children,
...props
}: Omit<ModalOverlayPrimitiveProps, "className" | "children"> & {
className?: string
children: React.ReactNode
}) {
return (
<ModalOverlayPrimitive
data-slot="dialog-overlay"
className={cn(
"fixed inset-0 isolate z-50 bg-black/10 duration-100 data-entering:animate-in data-entering:fade-in-0 data-exiting:animate-out data-exiting:fade-out-0 supports-backdrop-filter:backdrop-blur-xs",
className
)}
{...props}
>
{children}
</ModalOverlayPrimitive>
)
}
function Dialog({
className,
children,
showCloseButton = true,
isDismissable = true,
...props
}: Omit<ModalOverlayPrimitiveProps, "className" | "children"> &
Pick<React.ComponentProps<typeof ModalPrimitive>, "isDismissable"> & {
className?: string
children: React.ReactNode
showCloseButton?: boolean
}) {
return (
<DialogOverlay isDismissable={isDismissable} {...props}>
<ModalPrimitive
data-slot="dialog-content"
className={cn(
"fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none data-entering:animate-in data-entering:fade-in-0 data-entering:zoom-in-95 data-exiting:animate-out data-exiting:fade-out-0 data-exiting:zoom-out-95 sm:max-w-sm",
className
)}
>
<DialogPrimitive
data-slot="dialog"
className="[display:inherit] [gap:inherit] outline-none"
>
{children}
{showCloseButton && (
<DialogClose
variant="ghost"
className="absolute top-2 right-2"
size="icon-sm"
>
<XIcon />
<span className="sr-only">Close</span>
</DialogClose>
)}
</DialogPrimitive>
</ModalPrimitive>
</DialogOverlay>
)
}
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-header"
className={cn("flex flex-col gap-2", className)}
{...props}
/>
)
}
function DialogFooter({
className,
showCloseButton = false,
children,
...props
}: React.ComponentProps<"div"> & {
showCloseButton?: boolean
}) {
return (
<div
data-slot="dialog-footer"
className={cn(
"-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 sm:flex-row sm:justify-end",
className
)}
{...props}
>
{children}
{showCloseButton && <DialogClose variant="outline">Close</DialogClose>}
</div>
)
}
function DialogTitle({
className,
...props
}: Omit<React.ComponentProps<typeof Heading>, "slot">) {
return (
<Heading
slot="title"
data-slot="dialog-title"
className={cn(
"cn-font-heading text-base leading-none font-medium",
className
)}
{...props}
/>
)
}
function DialogDescription({
className,
...props
}: Omit<React.ComponentProps<"div">, "slot">) {
return (
<div
data-slot="dialog-description"
className={cn(
"text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
className
)}
{...props}
/>
)
}
export {
type DialogPrimitiveProps,
type DialogTriggerPrimitiveProps,
Dialog,
DialogClose,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogTitle,
DialogTrigger,
}
Update the import paths to match your project setup.
Usage#
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"<DialogTrigger>
<Button>Open</Button>
<Dialog>
<DialogHeader>
<DialogTitle>Are you absolutely sure?</DialogTitle>
<DialogDescription>
This action cannot be undone. This will permanently delete your account
and remove your data from our servers.
</DialogDescription>
</DialogHeader>
</Dialog>
</DialogTrigger>Composition#
Use the following composition to build a Dialog:
DialogTrigger
├── Button
└── Dialog
├── DialogHeader
│ ├── DialogTitle
│ └── DialogDescription
└── DialogFooterCustom Close Button#
Replace the default close control with your own button.
import { Button } from "@/components/ui/button"
import {
Dialog,import { Button } from "@/components/ui/button"
import {
Dialog,
DialogClose,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export function DialogCloseButton() {
return (
<DialogTrigger>
<Button variant="outline">Share</Button>
<Dialog className="sm:max-w-md">
<DialogHeader>
<DialogTitle>Share link</DialogTitle>
<DialogDescription>
Anyone who has this link will be able to view this.
</DialogDescription>
</DialogHeader>
<div className="flex items-center gap-2">
<div className="grid flex-1 gap-2">
<Label htmlFor="link" className="sr-only">
Link
</Label>
<Input
id="link"
defaultValue="https://ui.shadcn.com/docs/installation"
readOnly
/>
</div>
</div>
<DialogFooter className="sm:justify-start">
<DialogClose type="button">Close</DialogClose>
</DialogFooter>
</Dialog>
</DialogTrigger>
)
}
No Close Button#
Use showCloseButton={false} to hide the close button.
import { Button } from "@/components/ui/button"
import {
Dialog,import { Button } from "@/components/ui/button"
import {
Dialog,
DialogClose,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
export function DialogNoCloseButton() {
return (
<DialogTrigger>
<Button variant="outline">No Close Button</Button>
<Dialog showCloseButton={false}>
<DialogHeader>
<DialogTitle>No Close Button</DialogTitle>
<DialogDescription>
This dialog doesn't have a close button in the top-right
corner.
</DialogDescription>
</DialogHeader>
</Dialog>
</DialogTrigger>
)
}
Sticky Footer#
Keep actions visible while the content scrolls.
import { Button } from "@/components/ui/button"
import {
Dialog,import { Button } from "@/components/ui/button"
import {
Dialog,
DialogClose,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
export function DialogStickyFooter() {
return (
<DialogTrigger>
<Button variant="outline">Sticky Footer</Button>
<Dialog>
<DialogHeader>
<DialogTitle>Sticky Footer</DialogTitle>
<DialogDescription>
This dialog has a sticky footer that stays visible while the content
scrolls.
</DialogDescription>
</DialogHeader>
<div className="-mx-4 no-scrollbar max-h-[50vh] overflow-y-auto px-4">
{Array.from({ length: 10 }).map((_, index) => (
<p key={index} className="mb-4 leading-normal">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
))}
</div>
<DialogFooter>
<DialogClose variant="outline">Close</DialogClose>
</DialogFooter>
</Dialog>
</DialogTrigger>
)
}
Scrollable Content#
Long content can scroll while the header stays in view.
import { Button } from "@/components/ui/button"
import {
Dialog,import { Button } from "@/components/ui/button"
import {
Dialog,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
export function DialogScrollableContent() {
return (
<DialogTrigger>
<Button variant="outline">Scrollable Content</Button>
<Dialog>
<DialogHeader>
<DialogTitle>Scrollable Content</DialogTitle>
<DialogDescription>
This is a dialog with scrollable content.
</DialogDescription>
</DialogHeader>
<div className="-mx-4 no-scrollbar max-h-[50vh] overflow-y-auto px-4">
{Array.from({ length: 10 }).map((_, index) => (
<p key={index} className="mb-4 leading-normal">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
))}
</div>
</Dialog>
</DialogTrigger>
)
}
RTL#
To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import {// You will notice this example uses dir and data-lang attributes. // This is because this site is not RTL by default. // In your application, you won't need these.// See the RTL guide for more information.
"use client"
import {
useTranslation,
type Translations,
} from "@/components/language-selector"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogClose,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Field, FieldGroup } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
const translations: Translations = {
en: {
dir: "ltr",
values: {
openDialog: "Open Dialog",
editProfile: "Edit profile",
description:
"Make changes to your profile here. Click save when you're done.",
name: "Name",
username: "Username",
cancel: "Cancel",
saveChanges: "Save changes",
},
},
ar: {
dir: "rtl",
values: {
openDialog: "فتح الحوار",
editProfile: "تعديل الملف الشخصي",
description:
"قم بإجراء تغييرات على ملفك الشخصي هنا. انقر فوق حفظ عند الانتهاء.",
name: "الاسم",
username: "اسم المستخدم",
cancel: "إلغاء",
saveChanges: "حفظ التغييرات",
},
},
he: {
dir: "rtl",
values: {
openDialog: "פתח דיאלוג",
editProfile: "ערוך פרופיל",
description: "בצע שינויים בפרופיל שלך כאן. לחץ על שמור כשתסיים.",
name: "שם",
username: "שם משתמש",
cancel: "בטל",
saveChanges: "שמור שינויים",
},
},
}
export function DialogRtl() {
const { dir, t, language } = useTranslation(translations, "ar")
return (
<DialogTrigger>
<form>
<Button variant="outline">{t.openDialog}</Button>
<Dialog
className="sm:max-w-sm"
dir={dir}
data-lang={dir === "rtl" ? language : undefined}
>
<DialogHeader>
<DialogTitle>{t.editProfile}</DialogTitle>
<DialogDescription>{t.description}</DialogDescription>
</DialogHeader>
<FieldGroup>
<Field>
<Label htmlFor="name-1">{t.name}</Label>
<Input id="name-1" name="name" defaultValue="Pedro Duarte" />
</Field>
<Field>
<Label htmlFor="username-1">{t.username}</Label>
<Input id="username-1" name="username" defaultValue="@peduarte" />
</Field>
</FieldGroup>
<DialogFooter>
<DialogClose variant="outline">{t.cancel}</DialogClose>
<Button type="submit">{t.saveChanges}</Button>
</DialogFooter>
</Dialog>
</form>
</DialogTrigger>
)
}
API Reference#
See the React Aria documentation for more information.
Deploy your shadcn/ui app on Vercel
Trusted by OpenAI, Sonos, Adobe, and more.
Vercel provides tools and infrastructure to deploy apps and features at scale.
Deploy to Vercel