Components
Hold to Confirm
A button you press and hold to confirm.
Press and hold
<HoldToConfirm onConfirm={remove}>
Hold to delete
</HoldToConfirm>Installation
npx shadcn@latest add https://ui.zjkm.tech/r/hold-to-confirm.jsonimport { HoldToConfirm } from "@/components/hold-to-confirm"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
A button you press and hold until it fills, for actions that shouldn't happen on one stray click. Holding Space or Enter works the same from the keyboard, and letting go early cancels.
import { HoldToConfirm } from "@/components/hold-to-confirm";
export function DeleteAccount({ remove }: { remove: () => void }) {
return <HoldToConfirm onConfirm={remove}>Hold to delete account</HoldToConfirm>;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | The label. | |
onConfirm | () => void | Called after a full hold. | |
duration | number | 1200 | Milliseconds to hold. |
color | string | "#b91c1c" | Button colour. Keep it dark enough for white text. |
className | string | Classes for the button. |
With reduced motion, the button shows it's being held without the fill sweeping across.