Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Dialog for Astro

Build Astro modal dialogs with titles, descriptions, and actions. Explore shadcn style examples, installation, and keyboard behavior.

API Reference

Installation

bunx --bun shadcn@latest add @gnostic/dialog

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.

Keep actions visible while the content scrolls.

Scrollable Content

Long content can scroll while the header stays in view.

Props

DialogOptions

PropType
defaultOpen?boolean

Initial open state

Typeboolean
closeOnClickOutside?boolean

Close when clicking overlay

Typeboolean
closeOnEscape?boolean

Close when pressing Escape

Typeboolean
lockScroll?boolean

Lock body scroll when open

Typeboolean
alertDialog?boolean

Use alertdialog role for blocking confirmations

Typeboolean

Read 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.