Dialog Modal
Standard modal for confirmations, short forms, and detail views triggered by a button click. Ships with an overlay, focus trap, and close button already wired, do not rebuild those by hand.
Live preview
open in new tab ↗"use client"
import * as React from "react"
import { cn } from "@/lib/utils"
import { XIcon } from "lucide-react"
import { Dialog as DialogPrimitive } from "radix-ui"
import { Button } from "@/components/ui/button"
function Dialog(props) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />
}
function DialogTrigger(props) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
}
function DialogContent({ className, children, showCloseButton = true, ...props }) {
return (
<DialogPrimitive.Portal>
<DialogPrimitive.Overlay className="fixed inset-0 z-50 bg-black/50" />
<DialogPrimitive.Content
data-slot="dialog-content"
className={cn(
"fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg sm:max-w-lg",
className
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close className="absolute top-4 right-4 rounded-xs opacity-70 hover:opacity-100">
<XIcon />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Content>
</DialogPrimitive.Portal>
)
}
function DialogHeader({ className, ...props }) {
return <div className={cn("flex flex-col gap-2 text-center sm:text-left", className)} {...props} />
}
function DialogTitle({ className, ...props }) {
return <DialogPrimitive.Title className={cn("text-lg leading-none font-semibold", className)} {...props} />
}
function DialogDescription({ className, ...props }) {
return <DialogPrimitive.Description className={cn("text-sm text-muted-foreground", className)} {...props} />
}
export { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription }Block id: shadcn-dialogreact-tailwind · drop-in
More modal blocks
Want the whole site, not just the block?
We ship real client sites in 3 weeks — with blocks like this one, wired to your brand.

