Confirmation with confirm/cancel actions.
The ConfirmationModal component is a specialized modal designed for simple confirmation dialogs. It provides a streamlined way to ask users for confirmation before proceeding with an action, without the need to manually manage modal state or construct the modal UI.
Built on top of the Modal Manager, ConfirmationModal handles all the complexity of opening, closing, and managing the modal's state, allowing you to focus on the confirmation logic.
Use a ConfirmationModal when you need to:
Some guidelines:
isDanger for truly destructive or irreversible actionsThe simplest way to use a confirmation modal is with the useConfirmationModal hook, which returns a function that:
true if the user confirmed, or false if they cancelledYou can customize the button labels to make the action more explicit and contextual.
For destructive or irreversible actions, use the isDanger prop to style the confirm button in red, making it clear that this is a potentially dangerous action.
By default, confirmation modals can be dismissed by pressing Escape, clicking the overlay, or clicking the close button. For critical actions where the user must make an explicit choice, set isDismissable to false.
For the most critical destructive actions, you can require the user to type a specific phrase before the confirm button becomes enabled. This adds deliberate friction, ensuring the user fully understands the consequences before proceeding.
This pairs well with isDanger: true and isDismissable: false for maximum protection.
For more complex confirmation messages, you can pass custom components instead of plain strings to the message option.
This allows you to include formatted text, links, lists, or any other custom content in your confirmation modal.
When using custom message components:
message optionmessage option. The component will receive all modal data via @data, including any custom properties you pass to the modalWhile useConfirmationModal is the recommended approach, you can also use the ConfirmationModal component directly with the Modal Manager for more control over the modal's behavior.
You can provide optional callbacks that will be invoked when the user confirms or cancels the action. These callbacks can be synchronous or return a promise for async operations. While a callback is executing, the modal buttons are disabled and the modal cannot be dismissed.
Important notes about callbacks:
onConfirm is called when the user clicks the confirm buttononCancel is called when the user clicks the cancel button, presses ESC, or clicks the overlayconfirm() won't resolve until the callback completesSince ConfirmationModal is built on the Modal Manager, you can pass additional configuration options as a second argument to control modal behavior. See the Modal Manager documentation for all available options.
The confirmation modal accepts the following configuration options:
| Option | Type | Default | Description |
|---|---|---|---|
title | string | (required) | The title displayed in the modal header |
message | string or Component | (required) | The message displayed in the modal body. Can be a plain string or a custom component for more complex content. |
confirmLabel | string | "Confirm" | The label for the confirm button |
cancelLabel | string | "Cancel" | The label for the cancel button |
isDanger | boolean | false | Whether to style the confirm button as a danger action (red) |
isDismissable | boolean | true | Whether the modal can be dismissed via ESC key, overlay click, or close button |
onConfirm | () => void | Promise<void> | undefined | Optional callback invoked when the user confirms. Can be async. |
onCancel | () => void | Promise<void> | undefined | Optional callback invoked when the user cancels or dismisses the modal. Can be async. |
confirmationPhrase | string | undefined | A phrase the user must type exactly to enable the confirm button. Use for destructive actions where extra friction is needed. |
The useConfirmationModal hook returns a function that, when called, returns a promise that resolves to:
true - if the user clicked the confirm buttonfalse - if the user clicked cancel, pressed ESC, clicked the overlay, or clicked the close buttonWhen using the Modal Manager directly, the waitForClose promise resolves to an object with:
reason: Either 'confirm' or 'close'data: true if confirmed, false if cancelled