ReferenceDialogs
AlertDialog
A modal alert dialog for urgent messages that require acknowledgement
Import
Anatomy
Behavior
Use an alert dialog for an urgent message that interrupts the user and requires acknowledgement. Your application controls when it opens and supplies its content.
AlertDialog.Root adds alert semantics, while the other AlertDialog parts are re-exported from Dialog. For general modal content, including a player opened from a thumbnail, use Dialog.Root instead.
Use open with onOpenChange for controlled state, or defaultOpen for uncontrolled state. Root provides state without rendering an element, while Popup renders only while the dialog is open.
The close part and Escape close the dialog. The dialog stays rendered during a closing transition, then restores focus to the element that was focused before it opened.
Styling
Use the open and transition data attributes to style visibility and animations:
React renders separate backdrop and popup elements. Add a className to each part and style them independently:
Accessibility
The dialog uses role="alertdialog" and aria-modal="true". The title and description receive generated IDs that are connected with aria-labelledby and aria-describedby. Focus moves into the dialog when it opens, stays within it while open, and returns to the previously focused element when it closes. Content outside the dialog is inert while it is open. Pressing Escape closes the dialog.