Back to components
ElementOverlayFree

Confirm Dialog React component

A focused alert dialog for confirming an action, with default/warning/danger variants, an async-aware confirm button with a spinner and inline error, and a safety-first default focus.

About the Confirm Dialog component

Confirm Dialog is a small dialog that asks for confirmation before an action. It shows an icon, a title, an optional description and Cancel and Confirm buttons over a blurred backdrop. variant switches between default, warning and danger, which changes the icon and the color of the confirm button.

onConfirm can return a promise. While it runs, the confirm button shows a spinner and both buttons are disabled; the dialog closes when it resolves, and if it fails the dialog stays open with the error message. It uses role="alertdialog" with aria-modal, keeps Tab inside the dialog, locks page scrolling, closes on Escape and on a backdrop click (both can be turned off) and gives focus back to where it was when it closes.

When to use it

Use it before destructive or hard-to-undo actions: deleting a project, removing a team member, cancelling a subscription, discarding unsaved changes or publishing something.

For forms, longer content or more than two choices, use Modal. For a message that does not block the page after an action, use Alert Toast.

Installation

Add the Confirm Dialog component to your project with the shadcn CLI. It lands in components/confirm-dialog.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add @reactframe/confirm-dialog

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Related components

Hover Card
Free
Command Palette
Free
Context Menu
Free
Product Tour
Free
Cookie Consent Banner
Free
Avatar
Free