Hold to confirmPro
Press and hold to confirm destructive or important actions; letting go cancels.
pnpm dlx shadcn@latest add @lode/hold-to-confirmLet go early and it cancels.
When to use
- Destructive or expensive actions that shouldn't fire on a stray click: delete, release, wipe.
When not to use
- Frequent actions: holding every time is slow.
- Actions that need explanation: use a confirm dialog.
Installation
pnpm dlx shadcn@latest add @lode/hold-to-confirmPro components need an API key and the registry in components.json. See CLI and API keys.
1Install the dependencies
npm install motion lucide-react2Copy the source into your project
Usage
Import it from @/components/ui/hold-to-confirm after installing.
import { HoldToConfirm } from "@/components/ui/hold-to-confirm";
export function DeleteProject({ id }: { id: string }) {
return (
<HoldToConfirm tone="destructive" onConfirm={() => deleteProject(id)} doneLabel="Deleted">
Hold to delete
</HoldToConfirm>
);
}API reference
HoldToConfirm
A button that fills while held and confirms when full; releasing early drains it.
onConfirm
() => void | Promise<void>
Runs once the hold completes.
duration= 1400
number
Hold time in ms.
holdingLabel / doneLabel= "Keep holding…" / "Done"
ReactNode
Labels while held and after.
resetAfter= 2200
number
ms before returning to idle; 0 keeps the done state.
tone= "default"
"default" | "destructive"
Color.
| Prop | Type | Default | Description |
|---|---|---|---|
| onConfirm | () => void | Promise<void> | – | Runs once the hold completes. |
| duration | number | 1400 | Hold time in ms. |
| holdingLabel / doneLabel | ReactNode | "Keep holding…" / "Done" | Labels while held and after. |
| resetAfter | number | 2200 | ms before returning to idle; 0 keeps the done state. |
| tone | "default" | "destructive" | "default" | Color. |
Keyboard interactions
| Keys | Action |
|---|---|
| Hold SpaceorEnter | Fill and confirm |
| Release | Cancel before it fills |
Accessibility
- Described by a hidden hint: "Press and hold to confirm."
- Confirmation is announced politely.
- Works with keyboard holds, not just pointers.
Motion
- The fill grows linearly over the duration; releasing drains it in 350ms.
- Labels swap with a short blur and slide; the button presses in slightly while held.
Responsive behavior
- At least 176px wide; touch holds work and long-press menus are suppressed.
Performance
- The fill is a motion value; nothing re-renders per frame.
Notes for AI
- Use for one action at a time; don't put several in a row.
This page as Markdown, for assistants and coding agents:
/components/hold-to-confirm/markdownThe full library index for assistants is at /llms.txt.
Related
Lode·229 doc pages·llms.txt