Dialog for Astro
Build Astro modal dialogs with titles, descriptions, and actions. Explore shadcn style examples, installation, and keyboard behavior.
Installation
bunx --bun shadcn@latest add @gnostic/dialognpx shadcn@latest add @gnostic/dialogpnpm dlx shadcn@latest add @gnostic/dialogInstall component packages
bun add @data-slot/dialognpm install @data-slot/dialogpnpm add @data-slot/dialogCopy the files
src/components/ui/dialog/dialog-close.astrosrc/components/ui/dialog/dialog-content.astrosrc/components/ui/dialog/dialog-description.astrosrc/components/ui/dialog/dialog-footer.astrosrc/components/ui/dialog/dialog-header.astrosrc/components/ui/dialog/dialog-overlay.astrosrc/components/ui/dialog/dialog-panel.astrosrc/components/ui/dialog/dialog-portal.astrosrc/components/ui/dialog/dialog-title.astrosrc/components/ui/dialog/dialog-trigger.astrosrc/components/ui/dialog/dialog.astrosrc/components/ui/dialog/index.tssrc/components/ui/dialog/types.ts
Usage
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
<Dialog>
<DialogTrigger>Open</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you absolutely sure?</DialogTitle>
<DialogDescription>
Removing this draft deletes its saved content. Export a copy first if you need to keep it.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose variant="outline">Cancel</DialogClose>
<Button>Continue</Button>
</DialogFooter>
</DialogContent>
</Dialog>
Composition
Arrange the parts as shown for a Dialog:
Dialog
├── DialogTrigger
└── DialogContent
├── DialogHeader
│ ├── DialogTitle
│ └── DialogDescription
└── DialogFooter
Examples
With Form
Replace the default close control with your own button.
No Close Button
Use showCloseButton={false} to hide the close button.
With Sticky Footer
Keep actions visible while the content scrolls.
Scrollable Content
Long content can scroll while the header stays in view.
Props
DialogOptions
defaultOpen?boolean
Initial open state
booleancloseOnClickOutside?boolean
Close when clicking overlay
booleancloseOnEscape?boolean
Close when pressing Escape
booleanlockScroll?boolean
Lock body scroll when open
booleanalertDialog?boolean
Use alertdialog role for blocking confirmations
booleanRead the installed source for the complete prop types.
API Reference
See the data-slot docs for more information on interactivity.
Events
Dispatch these events on the dialog root. The root emits the outbound events.
Outbound events
| Event | Detail |
|---|---|
dialog:change |
{ open: boolean } |
Inbound events
| Event | Detail |
|---|---|
dialog:set |
{ open: boolean } |
When to use Dialog
Use a Dialog when a task needs a separate layer above the page. Compose title, description, content, and controls under one root. DialogPanel is useful for a separate body region; older direct content compositions remain supported.
Keyboard and behavior
The data-slot controller supplies modal focus and dismissal behavior. Give the dialog an accessible title, test Tab and Shift+Tab, and check focus after closing. A form inside the dialog still needs its own submission and error handling.
Theme and layout
The default panel stays centered and uses shared surface colors. Long content needs an intentional height limit and scrolling region. This Astro layout does not reproduce every Coss nested-dialog transform or mobile viewport animation.