structyl

Dialog

stable

A window overlaid on the primary content, rendering the content underneath inert.

Basic usage

Examples

Controlled

Manage open state externally to programmatically open or close the dialog.

State: closed

Form dialog

Use Dialog for edit flows that need focus trapping, labeled content and actions.

Features

  • Focus is automatically trapped while open.
  • Body scroll is locked.
  • Can be controlled or uncontrolled.
  • Esc closes the component automatically.
  • Manages screen-reader announcements with Title and Description.

Installation

bash
pnpm dlx structyl add dialog

Anatomy

Import the parts and compose them together.

tsx
<Dialog.Root>
  <Dialog.Trigger />
  <Dialog.Portal>
    <Dialog.Overlay />
    <Dialog.Content>
      <Dialog.Title />
      <Dialog.Description />
      <Dialog.Close />
    </Dialog.Content>
  </Dialog.Portal>
</Dialog.Root>

API Reference

Dialog.Root

Contains all the parts of a dialog.

PropTypeDefault
openboolean

Controlled open state.

defaultOpenboolean

Initial open state when uncontrolled.

onOpenChange(open: boolean) => void

Called when open state changes.

modalboolean

Whether interaction outside is disabled.

true

Dialog.Content

Contains content to be rendered in the open dialog.

PropTypeDefault
onEscapeKeyDown(event: KeyboardEvent) => void

Called when Escape is pressed.

onPointerDownOutside(event) => void

Called on outside pointer-down.

forceMountboolean

Force mounting for animation control.

Keyboard interactions

Adheres to the WAI-ARIA design pattern .

KeyDescription
SpaceOpens/closes the dialog from the trigger.
EnterOpens/closes the dialog from the trigger.
TabMoves focus to the next focusable element; trapped within content.
Shift + TabMoves focus to the previous focusable element.
EscCloses the dialog and moves focus to the trigger.
Dialog | structyl