Hold to Confirm

Hold to Confirm is a copy-paste React component that stops helps prevent a destructive action fired by a stray click before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/hold-to-confirm
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 2 extra npm packages
  • A11y guidance in docs

StopsHelps prevent a destructive action fired by a stray click

Was this component page useful?

How do I install Hold to Confirm?

pnpm dlx shadcn@latest add @bollard/hold-to-confirm

The files land in your project. They're yours to edit.

How do I use Hold to Confirm in React?

hold-to-confirm-usage.tsx
import { HoldToConfirm } from "@/components/ui/hold-to-confirm"

<HoldToConfirm
  variant="destructive"
  pendingLabel="Deleting…"
  confirmedLabel="Deleted"
  onConfirm={() =>
    new Promise<void>((resolve) =>
      setTimeout(() => {
        setLog("Workspace deleted.")
        resolve()
      }, 700),
    )
  }
>
  <Trash2 aria-hidden className="size-4" /> Delete workspace
</HoldToConfirm>

What input mistakes does Hold to Confirm catch?

  • Stray click or tap on a delete or other irreversible button
  • Releasing early: progress rewinds
  • Plain click: a hint explains to hold
  • Users who can't hold: a second press confirms instead

What props does Hold to Confirm accept?

HoldToConfirm props
PropTypeDefault
onConfirm* (required)

Fires once the button has been held for the full duration. Return a promise to show a pending state.

() => void | Promise<void>—
duration

How long the user must hold, in milliseconds.

number1200
variant

Visual intent. `destructive` is for delete and other irreversible actions.

keyof typeof variants"default"
size

Button size.

keyof typeof sizes"default"
holdHint

Shown briefly when someone clicks instead of holding, and read to screen readers.

string"Hold to confirm"
pendingLabel

Label while an async `onConfirm` is running.

React.ReactNode"Working…"
confirmedLabel

Label shown for a moment after the action is confirmed.

React.ReactNode"Done"
resetAfter

Milliseconds before the button resets after confirming. 0 keeps it confirmed.

number1600
confirmAgainLabel

Screen readers and switch access send a plain click and can't hold. Such a click arms the button and a second one within a few seconds confirms, so the safeguard stays without locking anyone out.

React.ReactNode"Press again"

* required. Also accepts the native props of <button> (className, aria-*, data-*…), passed through to it.

How is Hold to Confirm accessible?

  • Native button; Space or Enter can be held from the keyboard
  • Hint text is linked via aria-describedby and status changes use role=status
  • aria-busy while onConfirm is pending; icons are aria-hidden
  • Fill and label animations are reduced under reduced motion

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Authorize the destructive action on the server and make it idempotent.

  • Friction, not authorization: anyone who holds it confirms
  • The second-press path is quicker than holding, by design
  • Doesn't name the target; pair it with clear wording or a readback

What expensive mistakes does Hold to Confirm stop?

Helps prevent a destructive action fired by a stray click

Also known as

long press · press and hold · hold button · delete button · confirm button · mobile tap · destructive action

What dependencies does Hold to Confirm require?

Hold to Confirm facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameHold to Confirm
Registry identifier@bollard/hold-to-confirm
Install commandnpx shadcn@latest add @bollard/hold-to-confirm
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react, motion
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Hold to Confirm

How does Hold to Confirm protect destructive mutations?

Hold to Confirm prevents a destructive action fired by a stray click. Enforces deliberate friction against Stray click or tap on a delete or other irreversible button, Releasing early: progress rewinds, Plain click: a hint explains to hold, Users who can't hold: a second press confirms instead. Limitation: authorize hold-to-confirm mutations on the server.

How do I install hold-to-confirm with shadcn?

Run `npx shadcn@latest add @bollard/hold-to-confirm`. Sources added: registry/default/hold-to-confirm/hold-to-confirm.tsx. Package requirements: lucide-react, motion.

What props customize Hold to Confirm?

Hold to Confirm accepts `onConfirm`, `duration`, `variant`, `size`, `holdHint`. Configures long press, press and hold, hold button behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of hold-to-confirm?

Friction, not authorization: anyone who holds it confirms. The second-press path is quicker than holding, by design. Doesn't name the target; pair it with clear wording or a readback Server requirement: Authorize the destructive action on the server and make it idempotent.

How does Hold to Confirm meet accessibility guidelines?

Native button; Space or Enter can be held from the keyboard. Hint text is linked via aria-describedby and status changes use role=status. aria-busy while onConfirm is pending; icons are aria-hidden. Fill and label animations are reduced under reduced motion. Minimizes errors: accidental click deleted item, user tapped delete by mistake.

Which components pair with Hold to Confirm?