Hold to Confirm

Animated

A destructive button that fires only after a held press.

Source
$npx @dinachi/cli@latest add hold-to-confirm
variant
duration
resetAfter
confirmedLabel
disabled
data-agent-confirm

Usage

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

export function DeleteProject() {
  return (
    <HoldToConfirm onConfirm={() => deleteProject()} confirmedLabel="Deleted">
      Hold to delete
    </HoldToConfirm>
  )
}

Examples

A bar sweeps behind the label.
import { HoldToConfirm } from '@/components/ui/hold-to-confirm';

export function Example() {
  return (
    <HoldToConfirm onConfirm={deleteProject} confirmedLabel="Deleted">
      Hold to delete
    </HoldToConfirm>
  );
}

Notes

Motion tier

Needs motion. add --all skips it; install with add --motion or by name.

Variants

  • fill (default): a bar sweeps from the left behind the label.
  • ring: a stroke closes around the button. For square icon-only buttons.
  • border: the button's outline draws itself. For dense UI.

When to use it

  • Actions with no undo: deleting a project, revoking a key, ending a session.
  • Skip it for repeated actions; each use costs the full hold.
  • Skip it for reversible actions; offer undo instead.

Timing

  • Progress fills over duration and unwinds in 200ms.
  • Pressing again mid-unwind resumes from the current progress.
  • The hold survives a small drag off the button.

State attributes

data-holding is set while held, data-confirmed once confirmed. Style on these instead of :active.

API

onConfirm
agent
(details) => void
Runs when the hold completes or an agent presses. details.cancel() unwinds instead.
variant"fill" | "ring" | "border" = "fill"
How progress is drawn. See Variants.
durationnumber = 1600
Milliseconds the press must be held.
resetAfternumber = 1600
Milliseconds the confirmed state lasts. 0 stays confirmed.
confirmedLabelReactNode
Replaces the label while confirmed; announced.
holdHintstring = "Press and hold to confirm"
The description assistive tech reads.
fillClassNamestring
Class for the progress fill or stroke.
disabled
agent
boolean = false
Blocks people and agents.
renderReactElement | (props, state) => ReactElement
Swap the element, keep the behaviour.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as button.

Reads

label

The button's text, or its aria-label.

disabled

True when the button is disabled.

confirm

Set by default: a person approves each press.

Actions

press()

Completes the hold at once and runs onConfirm. Fails if already confirmed.

A press needs a person's approval by default: the step fails unless the agent's allow grants it, or data-agent-confirm="none" lifts it. The press runs through onConfirm, where isAgentChange(details) is true and details.cancel() refuses it; the agent is told the app refused. A disabled button refuses on its own.

await agent.act({
  steps: [{ ref: "Hold to delete", action: "press" }],
})

Accessibility

  • A native button. With a non-button render, disabled becomes aria-disabled.
  • holdHint is linked through aria-describedby.
  • confirmedLabel is announced from a polite live region beside the button.
  • Key repeat is ignored, so a held key is one hold.
  • Give a ring button an aria-label.
  • Reduced motion drops the press scale and keeps the progress.