Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Feedback

Alert dialog

A modal that asks the user to confirm an action before it runs, such as deleting data.

Selector: mui-alert-dialog

Import
import { AlertDialog } from '@mushilu-san/ui/feedback';
PreviewCode

Loading example…

Overview

Alert dialog is a modal that interrupts the user to confirm or cancel. It is modal (aria-modal="true") and linked to its body text with aria-describedby, so screen readers read the question with the choices.

Set destructive for actions that cannot be undone. The confirm button then uses the danger style. confirmed and cancelled tell the page what the user chose.

When to use

  • Confirming an irreversible action, such as deleting a project.
  • Warning before a change that affects other people.

When not to use

  • Showing information or a form. Use a dialog. Use Dialog instead.
  • A message that does not need an answer. Use an alert or a toast. Use Alert instead.

Guidelines

Do

  • Name the action in the confirm label, such as "Delete project".
  • Explain what will be lost in the body text.

Don't

  • Do not use "OK" and "Cancel" when the choice has consequences.
  • Do not open an alert dialog from another alert dialog.

Accessibility

Roles and attributes

ElementRoleNotes
dialogdialog (modal)aria-modal="true". Described by its body text with aria-describedby.

Keyboard

KeysAction
TabShiftTabCycles focus inside the dialog.
  • Escape is ignored on purpose. The user must choose one of the two actions, so the decision is never dismissed by accident.

API

AlertDialog

Selector: mui-alert-dialog

NameTypeDefaultDescription
headingrequiredstring— Question the user is asked. Labels the dialog.
confirmLabelstring'Confirm' Text of the confirm button. Default `Confirm`.
cancelLabelstring'Cancel' Text of the cancel button. Default `Cancel`.
destructivebooleanfalse Set to true for destructive actions — styles confirm button in danger color. Accepts attribute presence, e.g. <… destructive>.
NameTypeDefaultDescription
openbooleanfalse Whether the dialog is open. Two-way bindable with `[(open)]`.
NameTypeDescription
confirmedvoid Emits when the user chooses the confirm button.
cancelledvoid Emits when the user chooses the cancel button.

CSS parts

  • ::part(body)
  • ::part(cancel)
  • ::part(confirm)
  • ::part(footer)
  • ::part(header)
  • ::part(panel)
  • ::part(root)
  • ::part(surface)
  • ::part(title)

Tokens

  • --mui-color-surface-raised
  • --mui-color-danger
  • --mui-shadow-5
  • --mui-z-modal
  • --mui-color-focus-ring