AlertDialog

A dialog that needs an answer before it closes.

Base UI Alert DialogSource

Confirm an action

Use danger on the button that does the destructive act, not on the button that opens the dialog. The header has no close button.

Wait for the action

Control open to keep the dialog open while the delete runs. The button shows a spinner, and Escape does nothing until the delete ends.

Long content

The body scrolls, and the header and footer stay fixed. Set separator to draw a line above the actions.

Usage

These are defaults, not laws. Break one when you have a good reason, or when it makes the design more cohesive or more interesting.

  • Use an alert dialog only when the user must decide before going on, such as confirming a delete. A click outside does not close it. For anything else, use Dialog.
  • Name each action by what it does, such as "Delete project", not "OK". Put each one in AlertDialog.Close, unless the dialog waits for the action.
  • Every alert dialog needs an AlertDialog.Title, even when you leave out the header.

API

Props that the library adds. Every part also takes all the Base UI props.

AlertDialog.Body

PropTypeDefaultDescription
classNamestring–Classes that replace the default layout or padding.
childrenReactNode–The content of the dialog.

AlertDialog.Footer

PropTypeDefaultDescription
separatorbooleanfalseAdds a top divider and equal padding above and below the actions. Use it with long content.
classNamestring–Classes that replace the default layout or padding.
childrenReactNode–The actions of the dialog.

AlertDialog.Header

PropTypeDefaultDescription
childrenReactNode–The title text. The header labels the dialog with it.
showCloseButtonbooleanfalseShows a close button at the right of the header.
classNamestring–Classes for the header.

AlertDialog.Popup

PropTypeDefaultDescription
containerHTMLElement | ShadowRoot | RefObject | null–The element that the dialog renders into. The default is the document body.