Skip to content
Harness Design System Harness Design System Harness Design System

AlertDialog

beta

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 and accessible interface with built-in support for different themes and loading states.

Usage

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

Themes

Loading State

Anatomy

All parts of the AlertDialog component can be imported and composed as required.

<AlertDialog.Root>
<AlertDialog.Trigger />
<AlertDialog.Content title="Title">
{/* Dialog content */}
<AlertDialog.Cancel />
<AlertDialog.Confirm />
</AlertDialog.Content>
</AlertDialog.Root>

API Reference

Root

Controls the dialog behavior and provides context for theme and action handlers.

Prop
Required
Default
Type
onConfirmtrue() => void
onCancelfalse() => void
themefalse'default' | 'warning' | 'danger'
openfalseboolean
onOpenChangefalse(open: boolean) => void
loadingfalseboolean
childrentrueReactNode

Content

The main container for the alert dialog content.

Prop
Required
Default
Type
titletruestring
childrenfalseReactNode

Trigger

Wraps a control element that opens the dialog. Use asChild prop to customize the trigger element.

Prop
Required
Default
Type
asChildfalseboolean
childrentrueReactNode

Cancel

Optional cancel button. If not provided, a default “Cancel” button will be rendered.

Prop
Required
Default
Type
childrenfalseReactNode

Confirm

Optional confirm button. If not provided, a default “Confirm” button will be rendered.

Prop
Required
Default
Type
childrenfalseReactNode