Dialog
stableA 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 dialogAnatomy
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.
| Prop | Type | Default |
|---|---|---|
| open | booleanControlled open state. | — |
| defaultOpen | booleanInitial open state when uncontrolled. | — |
| onOpenChange | (open: boolean) => voidCalled when open state changes. | — |
| modal | booleanWhether interaction outside is disabled. | true |
Dialog.Content
Contains content to be rendered in the open dialog.
| Prop | Type | Default |
|---|---|---|
| onEscapeKeyDown | (event: KeyboardEvent) => voidCalled when Escape is pressed. | — |
| onPointerDownOutside | (event) => voidCalled on outside pointer-down. | — |
| forceMount | booleanForce mounting for animation control. | — |
Keyboard interactions
Adheres to the WAI-ARIA design pattern .
| Key | Description |
|---|---|
| Space | Opens/closes the dialog from the trigger. |
| Enter | Opens/closes the dialog from the trigger. |
| Tab | Moves focus to the next focusable element; trapped within content. |
| Shift + Tab | Moves focus to the previous focusable element. |
| Esc | Closes the dialog and moves focus to the trigger. |