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 API reference
Full props, types, defaults, and all 10 parts.
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. |