Skip to content

Confirm dialog

Pro

One 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.

Props

By name or description, across the 39 props below

ConfirmDialog 25 props

  • titletype ReactNodeRequired

    The question, short, naming the thing ("Remove Alex from the team?"). It names the dialog.

  • confirmLabeltype ConfirmLabelRequired

    The acting button's name: what happens ("Remove", "Delete post"), never "OK".

  • descriptiontype ReactNode

    What will happen, in a sentence or two. It describes the dialog to assistive tech.

  • childrentype ReactNode

    Anything else the decision needs, between the description and the actions: a password, a reason.

  • destructivetype booleandefault false

    The action can't be undone: the acting button takes the error role.

  • confirmDisabledtype booleandefault false

    The acting button can't be pressed yet, such as with a field still empty.

  • pendingtype booleandefault false

    The action is running (controlled): the acting button is pending, Cancel is disabled and nothing closes the dialog. A promise returned by onConfirm sets it too.

  • errortype ReactNode

    What went wrong, in the app's words. It shows in an alert inside the dialog, is announced, and focus moves to the acting button so Enter tries again. Hidden while a retry runs.

  • initialFocustype "content" | "cancel" | "confirm"default "cancel"

    Where focus starts: cancel, the least destructive choice; confirm; or content, the first control in children, for a field that must be filled first.

  • reftype Ref<HTMLDivElement>

    Ref to the root element.

  • opentype boolean

    Controlled open state, when not inside a DialogTrigger.

  • defaultOpentype booleandefault false

    Initial open state when uncontrolled, when not inside a DialogTrigger.

  • icontype ReactNode

    Icon above the title (which is then centred). Decorative. Not shown in full screen.

  • placementtype "center" | "top" | "bottom" | "start" | "end"default "center"

    Where a basic dialog sits: centred (the spec's default) or against one side of the window, keeping 24px from its edges on compact windows and 56px on wider ones. For any other position, align it with classNames.positioner (for example "items-start justify-end" for the top end corner). It also sets the motion's direction: centred or at the top the dialog slides down and grows downward as it enters, at the bottom up, and at the start or end along the x axis (mirrored in right-to-left layouts).

  • transitiontype "reveal" | "scale"default "reveal"

    How a basic dialog enters and leaves. reveal is the M3 dialog motion: it slides 50px away from the edge it sits against while its container grows from that edge, and its headline and content, then its actions, fade in. scale is the library's original pop, an extension beyond the M3 motion: the dialog fades in while it scales up from 90%, and fades out while it scales to 95%, from the centre (placement="center") or from the edge it sits against. Either way reduced motion keeps only the fades and instant turns the motion off. A full-screen dialog keeps its own motion and ignores it.

  • instanttype booleandefault false

    Skips the enter and exit motion: the dialog, its parts and the scrim appear and leave at once, and the dialog leaves the document as soon as it closes. Reduced motion already keeps only the fades.

Events

  • onOpenChangetype ((open: boolean) => void)

    Called when the dialog opens or closes; never to close while the action runs.

  • onConfirmtype (() => void | Promise<unknown>)

    Called on a press of the acting button, once. When it returns a promise the dialog is pending until that settles: it closes when the promise resolves and stays open when it rejects (give the words through error). When it returns nothing, a dialog with open stays open for the app to close, and one without closes at once.

  • onCanceltype (() => void)

    Called when the person backs out: the Cancel button, Escape or the back gesture.

  • onOpenedtype (() => void)

    Called when the dialog has finished opening: once its enter motion (the slide, the container's growth and every part's fade) has ended, or right after it opens with instant. Not called when it closes before then.

  • onClosedtype (() => void)

    Called when the dialog has finished closing: once its exit motion has ended and it has left the document, or right after it closes with instant.

Text

  • labelstype Partial<ConfirmDialogLabels>

    The words the dialog shows and announces, from the app's translations. English by default. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

ConfirmDialogActions 14 props

  • confirmLabeltype ConfirmLabelRequired

    The acting button's name: what happens ("Remove", "Save"), never "OK".

  • destructivetype booleandefault false

    The action can't be undone: the acting button takes the error role.

  • confirmDisabledtype booleandefault false

    The acting button can't be pressed yet, such as with a field still empty.

  • pendingtype booleandefault false

    The action is running: the acting button is pending (it keeps focus and announces labels.pending) and the action that backs out is disabled.

  • typetype "button" | "submit"default "button"

    submit makes the acting button submit the form it sits in.

  • autoFocustype "cancel" | "confirm"

    Which action takes focus when it mounts, in a dialog that opens on it.

  • confirmReftype Ref<HTMLButtonElement>

    The acting button's element.

  • reftype Ref<HTMLDivElement>

    Ref to the root element.

Events

  • onConfirmtype (() => void)

    Called on a press of the acting button; not while pending.

  • onCanceltype (() => void)

    Called on a press of the action that backs out.

Text

  • labelstype Partial<ConfirmDialogLabels>

    The words the row shows and announces, from the app's translations. English by default. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.

  • An action that can't be undone (destructive)

    Built

    Configuration · Remove, Content

  • Pending by promise, with a failure kept in the dialog (error)

    Built

    Configuration · Remove

  • In a trigger, with no state

    Built

    Configuration · Trigger

  • Content the decision needs (initialFocus="content", confirmDisabled)

    Built

    Configuration · Content

  • Leaving with unsaved changes

    Built

    Use case · Unsaved

  • The actions as a part, in a form dialog (ConfirmDialogActions)

    Built

    Use case · Form

Theming & tokens

Set the tokens below on the dialog or any ancestor. The dialog, its buttons and the failure's alert keep their own tokens, so a theme reaches them as anywhere else. className goes on the full-window layer around the dialog, as on the core Dialog; style each part with classNames: scrim, positioner, panel, icon, title, content, description, error, actions, cancel, confirm.

ConfirmDialog tokens
VariableDefaultPaints
--wm-confirm-dialog-gap16pxThe space between the description, the failure and the content.
--wm-confirm-dialog-description-colorvar(--md-sys-color-on-surface-variant)The description’s text.
--wm-confirm-dialog-destructive-label-colorvar(--md-sys-color-error)The acting button’s label and state layer, with `destructive`.