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.

PropTypeDefaultRequired
defaultOpenboolean
openboolean
onOpenChangefunction
idstring

A button that opens the dialog.

PropTypeDefaultRequired
asenumbutton

A layer that covers the inert portion of the view when the dialog is open.

PropTypeDefaultRequired
asenumdiv
forceMountboolean

Contains content to be rendered when the dialog is open.

PropTypeDefaultRequired
asenumdiv
forceMountboolean
onOpenAutoFocusfunction
onCloseAutoFocusfunction
onEscapeKeyDownfunction
onPointerDownOutsidefunction

A button that closes the dialog. This button should be distinguished visually from AlertDialog.Action buttons.

PropTypeDefaultRequired
asenumbutton

A button that closes the dialog. These buttons should be distinguished visually from the AlertDialog.Cancel button.

PropTypeDefaultRequired
asenumbutton

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.

PropTypeDefaultRequired
asenumh2

An accessible description to be announced when the dialog is opened. Alternatively, you can provide aria-describedby to AlertDialog.Content and exclude this component.

PropTypeDefaultRequired
asenump

Adheres to the Alert and Message Dialogs WAI-ARIA design pattern.

KeyDescription
SpaceOpens/closes the dialog.
EnterOpens/closes the dialog.
TabMoves focus to the next focusable element.
Shift + TabMoves focus to the previous focusable element.
EscCloses the dialog and moves focus to AlertDialog.Trigger.