Skip to main content

Alert Dialog

An alert dialog is a modal dialog that interrupts the user’s workflow to communicate an important message and acquire a response. Unlike a regular dialog, alert dialogs are always modal and cannot be dismissed by clicking outside or pressing Escape without an explicit user action.

Import

Basic Usage

Sub-components

Root

Groups all parts of the alert dialog. Doesn’t render its own HTML element. Key Props:
  • open (boolean): Whether the alert dialog is currently open
  • defaultOpen (boolean): Whether the alert dialog is initially open (default: false)
  • onOpenChange ((open: boolean, eventDetails) => void): Event handler called when the alert dialog is opened or closed
  • handle (DialogHandle): A handle to associate the alert dialog with an external trigger
  • actionsRef (React.RefObject): A ref to imperative actions (unmount, close)

Trigger

The button that opens the alert dialog.

Portal

Portals the alert dialog content to a different part of the DOM.

Backdrop

The backdrop that covers the screen when the alert dialog is open. The container for the alert dialog content.

Title

An accessible title for the alert dialog.

Description

An accessible description for the alert dialog.

Close

A button that closes the alert dialog.

Viewport

Defines the viewport element to which the dialog is confined.

Styling Example

Accessibility

  • Has role="alertdialog" to identify it as an alert dialog
  • Title and description are automatically linked via aria-labelledby and aria-describedby
  • Focus is trapped within the dialog when open
  • The backdrop and outside elements are inert when the dialog is open
  • Alert dialogs are always modal and require explicit user action to dismiss
  • Pressing Escape does not close the alert dialog (unlike regular dialogs)