Captain UI

Hold to confirm

Press and hold to confirm something you cannot undo. The fill runs at the speed of time; let go early and it snaps back.

npx shadcn@latest add https://captain-ui.vercel.app/r/hold-to-confirm.json

agent/pricing-table

14 commits, merged 2 days ago

Deploy key, staging

Ends in 4f2c, last used 06:40 today

Usage

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

<HoldToConfirm icon="trash" doneLabel="Deleted" onConfirm={deleteBranch}>
  Delete branch
</HoldToConfirm>

Props

PropTypeDefaultWhat it does
childrenReactNodeThe label, e.g. Delete branch.
onConfirm() => voidCalled once the hold completes.
durationnumber1600Hold length in ms. The fill is linear because time is.
iconIconNameLeading icon. Turns into a check when confirmed.
doneLabelReactNodeLabel after confirming, e.g. Deleted.
tone"danger" | "ink""danger"Colour of the fill.
size"sm" | "md""md"32 or 40px tall. The hit area is always 44px or more.
resetAfternumber | null2200Return to idle after this many ms; null keeps the done state.

Keyboard

Space (hold)
Fill
Enter (hold)
Fill

Accessibility

  • A real button; the hold length is announced through aria-describedby.
  • Space and Enter hold works the same as a pointer hold, and releasing early cancels.
  • The result is announced in a polite live region.
  • Dragging off the button by more than 24px cancels, so a slipped finger never confirms.