Skip to content
KaUI is under active development. If you run into a bug, please open an issue.

Confirm Action

Guards irreversible actions behind a confirm dialog with built-in async loading state on the confirm button.

pnpm dlx shadcn@latest add @kaui/confirm-action
import { ConfirmAction } from "@/components/ui/confirm-action";
<ConfirmAction
title="Delete item?"
description="This action cannot be undone."
confirmText="Delete"
confirmVariant="destructive"
action={deleteItem}
onSuccess={() => toast.success("Deleted")}
>
<Button variant="destructive">Delete</Button>
</ConfirmAction>

The child element becomes the dialog trigger. Any clickable element works — a button, an icon, a menu item.

When you need to open the dialog from outside the component tree (a dropdown item, a context menu, a table row action), omit children and drive the dialog with open + onOpenChange instead:

const [open, setOpen] = useState(false);
<ConfirmAction open={open} onOpenChange={setOpen} action={deleteItem} />;

The trigger can be anything. Here a ghost trash icon appears on row hover , invisible until the user signals intent, then confirms before the action runs.

Pass any icon or image to media to give the dialog visual context. The icon renders in a muted tile beside the title, making the dialog feel grounded in the action it’s describing.

Use onSuccess to access the data returned by action , useful for showing a confirmation message with context from the server response.

onError fires if action throws. The dialog stays open so the user can try again without re-triggering the confirmation flow.

When the trigger lives outside the component e.g a dropdown item, a context menu, a table row action , pass open and onOpenChange instead of children. The component becomes purely a dialog; you control when it opens.

PropTypeDefaultDescription
childrenReactNode—Trigger element that opens the dialog. Omit when controlling open externally.
openboolean—Controlled open state. Use when the trigger lives outside the component (dropdown item, context menu, table row action).
onOpenChange(open: boolean) => void—Called when the dialog requests an open state change. Provide alongside open to manage the dialog externally.
action() => Promise<TData> | TData—Async function executed when the user confirms
titleReactNode"Are you sure?"Dialog heading
descriptionReactNode"This action cannot be undone."Dialog body text
confirmTextReactNode"Continue"Label for the confirm button
cancelTextReactNode"Cancel"Label for the cancel button
confirmVariantButton variant"default"Visual style of the confirm button
loadingTextReactNodeconfirmTextText shown on the confirm button while the action runs
mediaReactNode—Icon or image rendered above the title inside the dialog
size"default" | "sm"—Controls dialog width
onSuccess(data: TData) => void—Called after action resolves , receives the return value
onError(error: TError) => void—Called if action throws
onSettled(data, error) => void—Called after either outcome