Skip to Content
Getting startedFoundationsComponentsPackagesTools

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.

error
neutral

Kind

`confirm` asks and offers Cancel; `alert` reports and offers one button, focused.

confirm
alert

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-dialog

Usage

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.

PropTypeDescription
openrequiredboolean
titlerequiredstring
descriptionrequiredReact.ReactNodeWhat will happen, read out with the title.
confirmLabelrequiredstringSays what the action does: "Delete workspace", not "OK".
cancelLabelstring
tone"error" | "neutral"error for an action that destroys something.
kind"alert" | "confirm"alert reports and offers one button; confirm asks.
pendingbooleanThe action is running: the confirm button spins and the dialog stays.
onConfirmrequired() => void
onCancelrequired() => voidCancel, 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 alert starts on its only button.
  • Escape and the close button cancel. Tab stays in the dialog, and focus returns on close.

On this page