Dialog
A dialog creates a window overlaid on top of a page window, rendering the content underneath inert.
Demo
Dialog
The dialog is commonly used for alerts, menus, and interactive prompts.
Features
- Focus is automatically trapped in a modal
- Manages screen reader announcements with dialog title and description
- Clicking on overlay closes the modal
- Esc key closes the modal
Anatomy
Directives
x-dialog
RequiredThe root element for the dialog.
Event | Description | detail |
---|---|---|
dialog:change | Whether the dialog is open or closed. | { open: boolean } |
Data Attribute | Values |
---|---|
[data-state] | open | closed |
x-dialog:trigger
RequiredTrigger button that opens or closes the dialog content.
Event | Description | detail |
---|---|---|
dialog:change | Whether the dialog is open or closed. | { open: boolean } |
Data Attribute | Values |
---|---|
[data-state] | open | closed |
x-dialog:content
RequiredThe content that will be shown or hidden.
Event | Description | detail |
---|---|---|
dialog:change | Whether the dialog is open or closed. | { open: boolean } |
Data Attribute | Values |
---|---|
[data-state] | open | closed |
x-dialog:overlay
Overlay for the page content. Closes the dialog when clicked on.
x-dialog:title
Dialog title announced to screen readers when opened.
x-dialog:description
Dialog description announced to screen readers when opened.
x-dialog:close
RequiredButton to close the dialog when opened.