Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Alert Dialog examples · Confirmation

Simple Confirmation Dialog Alert Dialog for React

A simple confirmation dialog with Cancel and Continue.

Framework
UI library

The basic confirmation: a title, a description of what will happen, and two buttons. This React alert dialog blocks the page until the reader confirms or cancels, which is what you want before deleting an account or any other step that can't be undone. It's shadcn.io's Alert Dialog on Base UI.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

When should I use an Alert Dialog instead of a Dialog?

Use an Alert Dialog for a decision the reader must make, like confirming a deletion. Use a Dialog for forms and content people may close at any time.

Can people dismiss it with Escape or a click outside?

Escape closes it. A click outside doesn't, so the reader has to pick Cancel or Continue.

What's the difference between the two buttons?

AlertDialogCancel is the safe choice, styled as an outline button, and always closes the dialog. AlertDialogAction is the primary button that runs the operation. Keep Cancel first and the action last.

How do I run an async operation on Continue?

Control the dialog's open state, give the action an isLoading state while the request runs, and close the dialog when it settles. Actions with Loading State shows the pattern.

Is it accessible?

Yes. The dialog has role="alertdialog", traps focus while open, is labelled by its title and description, and returns focus to the trigger when it closes.

Can the action use another button style?

Yes. AlertDialogAction takes the button variant: destructive for deletions, the default for normal confirmations. On Base UI, AlertDialogAction is a plain button that leaves the dialog open: control open and set it to false in the action's handler.