Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Dialog

A modal dialog that traps focus, locks page scroll, and closes on Escape. The backdrop, content, and focus behaviour all come from the Zag.js dialog machine; the component supplies markup and Tailwind styling.

The content renders into a portal on document.body, so it is never clipped by an ancestor’s overflow or trapped inside a stacking context.

React Dialoglive
import { Dialog } from "@/components/ui/dialog";
export function ConfirmAction() {
return (
<Dialog
trigger="Open dialog"
title="Delete workspace"
description="This action cannot be undone."
>
<p className="text-sm text-muted">
This removes every component in the workspace.
</p>
</Dialog>
);
}
Terminal window
npx @glaceon/cli add dialog --framework react # or svelte, solid

Style the dialog through the attributes Zag applies. The data-* values are stable and provide the intended styling surface:

Attribute Values Applied to
data-scope dialog every part
data-part trigger, backdrop, positioner, content, title, description, close-trigger matching part
data-state open, closed trigger, backdrop, content

Two behaviours are essential when writing CSS for this component:

  • The backdrop and content receive the hidden attribute while closed. Do not add a Tailwind display utility (block, flex) directly without conditional checks: a utility and the [hidden] rule have equal specificity, and the utility wins, which leaves a closed dialog visible.
  • The positioner is never hidden. Zag sets pointer-events: none on it inline while closed and hides the content inside it instead.
Prop Type Default Description
trigger string None Label for the button that opens the dialog
title string None Dialog title, wired to aria-labelledby
description string None Optional description, wired to aria-describedby
children ReactNode / Snippet / JSX.Element None Dialog body content
defaultOpen boolean false Open the dialog on first render
onOpenChange (details: { open: boolean }) => void None Called whenever the open state changes
className / class string None Applied to the content container
Key Behaviour
Enter / Space Opens the dialog when the trigger is focused
Tab Cycles focus within the dialog; focus does not escape to the page
Shift + Tab Cycles focus backwards within the dialog
Escape Closes the dialog and returns focus to the trigger

Focus trapping, scroll locking, role="dialog", aria-modal, and the aria-labelledby / aria-describedby wiring are provided by the Zag.js machine. The close button carries an explicit aria-label="Close", and both the trigger and the close button meet the 44px minimum tap target size (WCAG 2.2 SC 2.5.8).