Confirm dialog
ProOne dialog for "are you sure?": a question, what will happen, and two actions, locked while the action runs, with a failure kept inside it. Not an M3 component (@windmorph/react-pro).
import { ConfirmDialog, ConfirmDialogActions } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Purpose
One dialog for the moment an app asks "are you sure?" before something takes effect at once: deleting, removing, discarding unsaved work, signing out everywhere. It asks one question, says what will happen, and offers two actions: one that backs out and one named for what it does.
M3 has the basic dialog, and the core's Dialog is it. M3 defines nothing around a confirmation: where focus starts, what happens while the action runs, where a failure shows. This component decides those once. For anything that isn't a yes-or-no decision, use a Dialog.
Behaviour
- It is an alert dialog, small at every width. Escape and the back gesture back out as Cancel does, through
onCancel; a press on the scrim does nothing, and there is no close button. confirmLabelis required and says what happens ("Remove", "Delete post"), never "OK". Both actions are text buttons, as M3 asks of dialogs, with the one that backs out first.- While the action runs the acting button is pending, Cancel is disabled and nothing closes the dialog, so the action can't be abandoned or pressed twice. Set
pendingyourself, or return a promise fromonConfirm: the dialog is pending until it settles, closes when it resolves and stays open when it rejects. - When
onConfirmreturns nothing, a dialog withopenstays open for you to close, and one in aDialogTriggercloses at once. - A failure stays in the dialog: pass your words as
error. It shows in an alert above the content, is announced, and focus moves to the acting button so Enter tries again. It hides while a retry runs. destructivemarks an action that can't be undone: the acting button takes theerrorrole. The label still names the action, so colour is never the only sign.- Anything else the decision needs (a password, a reason, a one-time code) goes in as children, between the description and the actions.
- It opens over another dialog or a sheet, and Escape closes only the one on top.
The actions as a part
ConfirmDialogActions is the same row the dialog uses, for a form in a core Dialog: Cancel, then one acting button with pending. With type="submit" the acting button submits the form it sits in.
When not to use
For anything that isn't a yes-or-no decision use a Dialog; for an action that can be undone, do it and offer Undo in a Snackbar.
See also
- Dialog: A modal surface for a focused task or a decision, with a title, content and actions, or full screen on compact windows.
- Alert: A message that stays until it's resolved: a form's error, a page's warning, a system notice. Error, info, success, warning and neutral, tonal or outlined. Not an M3 component (@windmorph/react-pro).
- Snackbar: A brief message with an optional action and dismiss, queued through a host.