ConfirmDialog
"Are you sure?" as one component, built on Modal.
Examples
Playground
Tone
The confirm button carries the action's tone. `error` for what destroys something; `neutral` for a consequential step that destroys nothing.
Kind
`confirm` asks and offers Cancel; `alert` reports and offers one button, focused.
Pending
Confirm, and the button shows the action running for a moment. Escape and Cancel do nothing until it finishes, so a running action is never abandoned half way.
Install
npx shadcn add @hipuku/confirm-dialogUsage
import { ConfirmDialog } from '@/components/haus/components/ConfirmDialog'
<ConfirmDialog
open={open}
title="Delete workspace?"
description="Its records and history are deleted with it."
confirmLabel="Delete workspace"
tone="error"
pending={deleting}
onConfirm={deleteWorkspace}
onCancel={() => setOpen(false)}
/>API
ConfirmDialog also takes its element's own attributes and forwards its ref.
| Prop | Type | Description |
|---|---|---|
openrequired | boolean | |
titlerequired | string | |
descriptionrequired | React.ReactNode | What will happen, read out with the title. |
confirmLabelrequired | string | Says what the action does: "Delete workspace", not "OK". |
cancelLabel | string | |
tone | "error" | "neutral" | error for an action that destroys something. |
kind | "alert" | "confirm" | alert reports and offers one button; confirm asks. |
pending | boolean | The action is running: the confirm button spins and the dialog stays. |
onConfirmrequired | () => void | |
onCancelrequired | () => void | Cancel, Escape, and the close button. Not called while pending. |
Kinds and tone
kind="confirm"asks, with Cancel and the confirm button. The default.kind="alert"reports, with one button and nothing to cancel.tone="error"colours the confirm button for an action that destroys something.
Write confirmLabel as the action, "Delete workspace" rather than "OK": it is the last thing a
reader hears before acting.
While it runs
Set pending while the action runs. The confirm button shows it is working, and Cancel, Escape
and the close button do nothing, so the action is not abandoned half way.
A click on the backdrop never dismisses a ConfirmDialog, and that cannot be turned on: the point is a deliberate answer.
Accessibility
- Announced as an alert dialog, with its description read alongside the title.
- Focus starts on Cancel, so Enter does the safe thing. An
alertstarts on its only button. - Escape and the close button cancel. Tab stays in the dialog, and focus returns on close.