Alert Dialog
A modal dialog that interrupts the user with important content and expects a response.
Features
- Focus is automatically trapped.
- Can be controlled or uncontrolled.
- Manages screen reader announcements with `Title` and `Description` components.
- Esc closes the component automatically.
Install the component from your command line.
Import the components and piece the parts together.
Create your styled alert dialog component from the primitive parts.
Contains all the parts of an alert dialog.
Prop | Type | Default | Required |
---|---|---|---|
defaultOpen | boolean | ||
open | boolean | ||
onOpenChange | function | ||
id | string |
A button that opens the dialog.
Prop | Type | Default | Required |
---|---|---|---|
as | enum | button |
A layer that covers the inert portion of the view when the dialog is open.
Prop | Type | Default | Required |
---|---|---|---|
as | enum | div | |
forceMount | boolean |
Contains content to be rendered when the dialog is open.
Prop | Type | Default | Required |
---|---|---|---|
as | enum | div | |
forceMount | boolean | ||
onOpenAutoFocus | function | ||
onCloseAutoFocus | function | ||
onEscapeKeyDown | function | ||
onPointerDownOutside | function |
A button that closes the dialog. This button should be distinguished visually from AlertDialog.Action
buttons.
Prop | Type | Default | Required |
---|---|---|---|
as | enum | button |
A button that closes the dialog. These buttons should be distinguished visually from the AlertDialog.Cancel
button.
Prop | Type | Default | Required |
---|---|---|---|
as | enum | button |
An accessible name to be announced when the dialog is opened. Alternatively, you can provide aria-label
or aria-labelledby
to AlertDialog.Content
and exclude this component.
Prop | Type | Default | Required |
---|---|---|---|
as | enum | h2 |
An accessible description to be announced when the dialog is opened. Alternatively, you can provide aria-describedby
to AlertDialog.Content
and exclude this component.
Prop | Type | Default | Required |
---|---|---|---|
as | enum | p |
Adheres to the Alert and Message Dialogs WAI-ARIA design pattern.
Key | Description |
---|---|
Space | Opens/closes the dialog. |
Enter | Opens/closes the dialog. |
Tab | Moves focus to the next focusable element. |
Shift + Tab | Moves focus to the previous focusable element. |
Esc | Closes the dialog and moves focus to AlertDialog.Trigger . |