Xzero UI
Pro library

Hold to confirm

Confirm a destructive action by holding, not tapping.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/hold-to-confirm
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/hold-to-confirm

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { HoldToConfirm } from "@/components/xzero/hold-to-confirm/hold-to-confirm";

export function DeleteProject({ onDelete }: { onDelete: () => void }) {
  return (
    <HoldToConfirm
      label="Hold to delete project"
      confirmedLabel="Deleted"
      duration={1500}
      onConfirm={onDelete}
    />
  );
}

Examples

Keep holding hint

const [holding, setHolding] = useState(false);

<HoldToConfirm label="Hold to revoke key" onConfirm={revoke} onHoldChange={setHolding} />
<p aria-hidden="true">{holding ? "Keep holding" : ""}</p>

API reference

HoldToConfirm

A button that commits only after a press is held, with a fill that tracks the hold and rewinds on early release.

PropTypeDefaultDescription
label (required)string–Instruction and action, such as "Hold to delete project".
onConfirm (required)() => void–Called once when the hold completes.
confirmedLabelstring"Done"Label after the hold completes.
durationnumber1200Hold length in milliseconds.
iconReactNode<Trash2 />Leading icon. Replaced by a drawn check when done.
tone"danger" | "neutral""danger"Fill color.
confirmedboolean–Controls the done state. Set back to false to reset; leave undefined to let the button manage it.
onHoldChange(holding: boolean) => void–Reports when a hold starts and ends, for hints like "Keep holding".
...propsButtonHTMLAttributes<HTMLButtonElement>–Forwarded to the button, except children and onClick.

Keyboard interactions

KeysAction
Space / Enter (hold)Fills the button; releasing early rewinds it.
Tab awayCancels an active hold.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in gestures

Guidance for AI tools

Hold to confirm: Confirm a destructive action by holding, not tapping. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components