Documentation

Confirm button

A destructive action in two presses: the first arms it and says what will happen, the second runs it.

WebBetaActions

Web only — React, from @krizaka/ui/confirm-button. Beta: its API may still change in a minor version.

When to use

  • For a destructive action on one item, in place: delete a comment, remove a member, leave a group.
  • When a dialog would be too heavy and an undo is not possible.

When not to use

  • When the consequences need explaining, or several things are affected.Use instead: Dialog
  • For an action that is not destructive.Use instead: Button
  • When the action can be undone: run it at once and offer “Undo” in a toast.Use instead: Toast

Installation

Install

npm install @krizaka/ui@beta @krizaka/tailwind@beta @krizaka/tokens@beta tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Import

import { ConfirmButton } from "@krizaka/ui/confirm-button";

Examples

Icon, idle

An icon named by label.

Armed

After the first press: the danger border and tint, the words legible.

With words

Once armed, armedContent replaces the words.

Props

A two-step button: press to arm, press again within timeoutMs to confirm. State: data-armed.

PropTypeDefaultDescription
confirmLabelrequiredstring—What the second press does, in words — shown and announced once armed ("Delete for good?"). Passed translated.
onConfirmrequired() => void—Runs on the second press.
armedContentReactNode—What it shows once armed (default: its children, then confirmLabel).
labelstring—The accessible name while idle, for an icon-only button (the confirm label names it once armed).
loadingboolean—Disables and signals the wait (aria-busy, data-loading) — the product adds a spinner if it wants one.
onArmedChange((armed: boolean) => void)—Notified when it arms and disarms.
shape"rounded" | "pill"roundedrounded · pill.
size"icon" | "sm" | "md" | "lg"mdsm · md · lg, or icon (a square).
timeoutMsnumber4000Disarms after this many milliseconds (4000 by default).
variant"danger" | "primary" | "secondary" | "outline" | "ghost"ghostThe look: primary (the accent), secondary (a raised surface), outline, ghost, danger.

Accessibility

  • Once armed, confirmLabel names the button and is announced politely.
  • An icon-only confirm button needs label while idle.
  • The armed state is data-armed: style it with the danger tint, the words stay a text role.

Keyboard

KeysAction
Enter / SpaceArms, then confirms.
EscDisarms; so does moving the focus away.

Best practices

  • confirmLabel says the consequence as a question: “Delete for good?”.
  • Keep timeoutMs short (4 s by default): an armed button left on screen is a trap.
  • Never use window.confirm for this.

Generated from the code of @krizaka/ui 2.0.0-beta.6: its meta.ts, its examples and its types.Edit this documentation on GitHub

On this page