Skip to content

Alert Dialog

The AlertDialog component is a specialized variant of Dialog designed for scenarios where users need to confirm or cancel potentially destructive or irreversible actions. It provides a consistent, accessible interface with built-in support for different themes and a loading state.

Each AlertDialog is opened by its own AlertDialog.Trigger — the button in each row below opens the dialog. The theme sets both the header icon and the confirm button’s color, and loading keeps the dialog open with a spinner while the confirm action runs.

Installation

import { AlertDialog, Button } from "@harnessio/ui/components";
// ...
return (
<AlertDialog.Root onConfirm={() => handleDelete()} theme="danger">
<AlertDialog.Trigger>
<Button>Delete item</Button>
</AlertDialog.Trigger>
<AlertDialog.Content title="Delete item">
Are you sure you want to delete this item? This action cannot be undone.
<AlertDialog.Cancel>Cancel</AlertDialog.Cancel>
<AlertDialog.Confirm>Delete</AlertDialog.Confirm>
</AlertDialog.Content>
</AlertDialog.Root>
);

The Trigger wraps whatever control should open the dialog — pass a Button (or any interactive element) as its single child. If you omit AlertDialog.Cancel and AlertDialog.Confirm, a default “Cancel” and “Confirm” pair is rendered for you.