Hold to Confirm, animated React component
A destructive button you have to press and hold: the fill sweeps across, letting go early springs it back, and finishing bursts into a tick with an undo toast that counts down.
- Pro
- Inputs & Controls
- Spring
Rises while you hold, chimes when it confirms and hushes if you let go early. Sound is off on this site until you switch it on.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| onConfirm | () => void | — | Called once the hold completes. |
| onUndo | () => void | — | Called when Undo is pressed before the countdown runs out. |
| holdMs | number | 1500 | How long the button must be held, in ms. |
| label | string | "Hold to Delete" | Resting label. |
| holdingLabel | string | "Keep holding…" | Label revealed by the fill. |
| doneLabel | string | "Project deleted" | Toast text after confirming. |
| color | string | "#ff3b30" | Fill and text colour. |
| autoplay | boolean | false | Shows a short hold-and-release tease until someone interacts. |
| enableSound | boolean | true | Plays interface sounds on interaction. They follow the sound switch (setSoundsEnabled, on by default) and stay silent on hover. Autoplay makes the same sounds once the visitor has used the page. Pass false to silence this component. |
Add it to your project
- 1
Set up your project once
You need a Next.js project with Tailwind CSS and the
@/import alias. In its root folder, run this once. It createscomponents.jsonand thecn()helper insrc/lib/utils.ts:npx shadcn@latest init -d
Starting from nothing? The Quick Start walks through the whole thing.
- 2
Connect the registry with your API key
Hold to Confirm is a Pro item, so the CLI has to send your API key. Do this once per project:
- Create a key at nexus-ui.com/dashboard/api-key. Copy it straight away: it starts with
nxs_and is shown only once. - In your project root, next to
package.json, create a file named.env.localwith this line, using your own key:NEXUS_API_KEY=nxs_your_key_here
- Open
components.jsonand add this entry inside the outermost braces, next to"aliases". Leave{name}and${NEXUS_API_KEY}exactly as written; the CLI fills them in:"registries": { "@nexus-labs": { "url": "https://www.nexus-ui.com/api/registry/{name}", "headers": { "Authorization": "Bearer ${NEXUS_API_KEY}" } } }
- Create a key at nexus-ui.com/dashboard/api-key. Copy it straight away: it starts with
Hold to Confirm questions
How do I install Hold to Confirm and run code when it completes?
Run `npx shadcn@latest add @nexus-labs/hold-to-confirm`, which depends on framer-motion. `onConfirm` is called once the hold completes, and `onUndo` is called if Undo is pressed on the toast before its 5 second countdown ends. It is a Pro component, so it needs a Pro plan and an API key; key setup is on the CLI docs page (/docs/cli).
How long do you have to hold, and what can I relabel?
`holdMs` is the hold time in milliseconds (default 1500). `label` defaults to "Hold to Delete", `holdingLabel` to "Keep holding…" and `doneLabel` to "Project deleted", and `color` (default `#ff3b30`) sets the fill and text colour.
Does it work with the keyboard and on touch screens?
Yes. Holding Space or Enter fills the button just like holding the pointer, and releasing early or moving the pointer off the button springs the fill back without calling `onConfirm`. The button has `touch-none` and its context menu is blocked, so a long press on mobile does not open a menu.
How is the hold effect built, and does it respect reduced motion?
A Framer Motion value animates linearly from 0 to 1 over `holdMs` and drives a `scaleX` fill and a `clip-path` that reveals the "Keep holding" label. The tick and burst are SVG and DOM, with no canvas. The component does not check prefers-reduced-motion.
Does it make sound, and how do I turn it off?
Rises while you hold, chimes when it confirms and hushes if you let go early. Sounds are synthesised with the Web Audio API, so there are no audio files, and they only play after a click or key press. Pass `enableSound={false}` to silence this component, or call `setSoundsEnabled(false)` from `@/lib/ui-sounds` to switch every sound off at once. The CLI installs `@/lib/ui-sounds` with the component.