Skip to content

AlertDialog

A modal confirmation dialog for destructive or irreversible actions.

Delete item?

This action cannot be undone.

() => {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<Button label="Delete item" onClick={() => setIsOpen(true)} />
<AlertDialog
actionLabel="Delete"
description="This action cannot be undone."
isOpen={isOpen}
onAction={() => setIsOpen(false)}
onOpenChange={setIsOpen}
title="Delete item?"
/>
</>
);
}

Delete item?

Cancel receives initial focus, and the header has no implicit close action.

() => {
const [isOpen, setIsOpen] = useState(true);
return (
<>
<Button label="Reopen alert dialog" onClick={() => setIsOpen(true)} />
<AlertDialog
actionLabel="Delete"
description="Cancel receives initial focus, and the header has no implicit close action."
isOpen={isOpen}
onAction={() => setIsOpen(false)}
onOpenChange={setIsOpen}
title="Delete item?"
/>
</>
);
}

Delete item?

This action cannot be undone.

() => {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<Button label="Delete item" onClick={() => setIsOpen(true)} />
<AlertDialog
actionLabel="Delete"
description="This action cannot be undone."
isActionLoading
isOpen={isOpen}
onAction={() => setIsOpen(false)}
onOpenChange={setIsOpen}
title="Delete item?"
/>
</>
);
}

Delete item?

This action cannot be undone.

() => {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<Button label="Delete item" onClick={() => setIsOpen(true)} />
<AlertDialog
actionLabel="Delete"
cancelLabel="No, keep it"
description="This action cannot be undone."
isOpen={isOpen}
onAction={() => setIsOpen(false)}
onOpenChange={setIsOpen}
title="Delete item?"
/>
</>
);
}

Archive project?

Archived projects can be restored later.

() => {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<Button label="Archive project" onClick={() => setIsOpen(true)} />
<AlertDialog
actionLabel="Archive"
actionVariant="primary"
description="Archived projects can be restored later."
isOpen={isOpen}
onAction={() => setIsOpen(false)}
onOpenChange={setIsOpen}
title="Archive project?"
/>
</>
);
}

Wide dialog

This dialog uses a custom width of 600px.

() => {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<Button label="Open wide dialog" onClick={() => setIsOpen(true)} />
<AlertDialog
actionLabel="Confirm"
description="This dialog uses a custom width of 600px."
isOpen={isOpen}
onAction={() => setIsOpen(false)}
onOpenChange={setIsOpen}
title="Wide dialog"
width={600}
/>
</>
);
}

Are you sure you want to permanently delete this project and all of its contents?

This action will permanently delete all associated data, including files, comments, activity history, and any linked resources. Once deleted, this information cannot be recovered. Please make sure you have backed up anything you need before proceeding.

() => {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<Button label="Delete project" onClick={() => setIsOpen(true)} />
<AlertDialog
actionLabel="Delete"
description="This action will permanently delete all associated data, including files, comments, activity history, and any linked resources. Once deleted, this information cannot be recovered. Please make sure you have backed up anything you need before proceeding."
isOpen={isOpen}
onAction={() => setIsOpen(false)}
onOpenChange={setIsOpen}
title="Are you sure you want to permanently delete this project and all of its contents?"
/>
</>
);
}
() => {
const alert = useAlertDialog();
return (
<>
<Button
label="Open imperative alert"
onClick={() =>
alert.show({
actionLabel: 'Archive',
actionVariant: 'primary',
description: 'Archived projects can be restored later.',
onAction: alert.hide,
title: 'Archive project?',
})
}
/>
{alert.element}
</>
);
}

A modal confirmation dialog for destructive or irreversible actions.

PropTypeDefaultDescription
actionLabel*string—Action button label.
actionVariant"destructive" | "primary"'destructive'Visual variant for the action button.
cancelLabelstring'Cancel'Cancel button label.
classNamestring—Additional CSS class names applied to the dialog.
data-testidstring—Test ID applied to the dialog.
description*string—Consequence description.
isActionLoadingbooleanfalseWhether the action button is loading.
isOpen*boolean—Whether the dialog is open.
onAction*() => void—Called when the primary action is clicked.
onOpenChange*(isOpen: boolean) => void—Called when the dialog requests an open-state change.
refRef<HTMLDialogElement>—Ref forwarded to the dialog element.
styleCSSProperties—Inline styles applied to the dialog.
title*string—Dialog title.
widthSizeValue400Dialog width. Numbers are pixels, strings are used as-is.