Skip to content
English

How it works

A button that confirms only when held. One CSS variable, --_p (0 to 1), drives everything: each frame JS writes time held ÷ duration, the fill scales from the left, and a white text layer is clipped to the same edge, so text turns white as the fill passes. Releasing, leaving the button or losing focus snaps back in 160ms. All texts share one grid cell, so the size never changes. The fill is a gradient that is lighter behind and full strength at its leading edge; when the action completes the button lifts with a soft glow of its own colour.

Use it for

  • Irreversible or costly actions such as deleting a record, cancelling an order or unlinking a device, in place of a confirm dialog.
  • Destructive confirmations that must work on both mobile and desktop without interrupting the page.
  • Ordinary confirmations that need protection from slips (tone="primary"), such as emptying a cart.

Look elsewhere when

  • Ordinary, reversible actions: use a plain button.
  • Consequences that need explaining, or a typed confirmation: use a dialog.
  • Several hold buttons side by side: keep it for the single most dangerous action.

Usage

import { useRef } from 'react'
import { HoldToConfirm } from './HoldToConfirm.jsx'

export function DeleteProject({ projectId }) {
  const ref = useRef(null)
  return (
    <HoldToConfirm
      ref={ref}
      tone="danger"
      duration={1200}
      label="Hold to delete project"
      holdingLabel="Keep holding…"
      loadingLabel="Deleting…"
      doneLabel="Project deleted"
      // Return a Promise: a loading state shows meanwhile, and a rejection snaps back
      onConfirm={() => api.deleteProject(projectId)}
    />
  )
  // To allow another try: ref.current?.reset(), or give the component a new key
}

Props

PropTypeDefaultWhat it does
durationnumber1200How long to hold before it fires, in ms. Minimum 200.
labelReactNode'Hold to confirm'Default text. Say what the hold does, such as “Hold to delete project”. Also the accessible name.
holdingLabelReactNode'Keep holding…'Text while held. It appears 120ms after pressing, so a quick tap does not flash it.
loadingLabelReactNode'Working…'Shown with a spinner while the Promise from onConfirm is pending.
doneLabelReactNode'Confirmed'Shown with a checkmark when finished.
againLabelReactNode'Press again to confirm'For screen readers and voice control, which cannot hold: shown and announced after the first activation. A second activation within 4 seconds confirms.
labelsobject—Replaces built-in text that has no prop of its own (hint: (seconds) => string, the description read by screen readers). Shallow-merged over the English defaults.
onConfirm() => void | Promise—Called when the fill completes. A returned Promise shows loading; resolving shows done, rejecting snaps back so the user can retry.
tone'danger' | 'primary' | 'ink''danger'Colour. Danger for delete, close or cancel; primary or ink (neutral, inverts in dark) for ordinary confirmations that need protection from slips.
blockbooleanfalseFills the width of the parent.
disabledbooleanfalseDisables the button. Disabling it while held cancels at once.
refRef<{ reset(), focus() }>—reset returns to the initial state and discards a pending result; focus focuses the button. A new key also works.
...restButtonHTMLAttributes—Other attributes go to the <button>. Pointer and key handlers you pass run before the component's own.

Accessibility

  • A native <button>: holding Space or Enter is timed the same way, and releasing, switching windows or moving focus cancels.
  • aria-describedby gives the hint “Hold for about N s to confirm”; replace it through labels.hint.
  • Screen reader and voice clicks have no hold, so they become a two-step confirmation: the first announces “Press again to confirm”, a second within 4 seconds fires.
  • Pressed, working and done states are announced through a live region; the button is 44px tall.
  • Reduced motion keeps the fill (it is timing feedback) and removes the snap-back, press scale, text movement and checkmark drawing.

Motion

Fill advances linearly over the duration (1200ms by default); an early release snaps back in 160ms ease-in. Text enters in 240ms with a 6px rise, and the checkmark draws in 360ms. On completion a soft glow of the tone colour fades in over 360ms.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

HoldToConfirm.jsxhold-to-confirm.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Buttons
Aurora rim button comes with Pro. Its preview shows once you unlock it.
Bite button comes with Pro. Its preview shows once you unlock it.