Press and hold, or hold Space. Let go early to cancel.
Playground
Change the props and copy the code. The controls come from the component's TypeScript types.
Props
import { HoldButton } from "@/components/ui/loaders";<HoldButton>Hold to delete</HoldButton>Installation
$ pnpm dlx shadcn@latest add @synccn/hold-buttonFirst time in this project? Connect synccn with one command.
Usage
import { HoldButton } from "@/components/ui/loaders";<HoldButton onConfirm={remove}>Hold to delete</HoldButton>API reference
Generated from the component's TypeScript types, so it always matches the code.
HoldButton
Button that has to be held to confirm a risky action. Releasing early cancels. Keyboard users hold Space or Enter.
- duration
numberDefault
1500Milliseconds the button must be held.
- onConfirm
() => voidCalled once the hold completes.
- variant
"destructive" | "default"Default
"destructive"Colour of the fill.
- children
React.ReactNodeDefault
"Hold to delete"Content to render.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
Keyboard
- SpaceorEnterHold to confirm; release early to cancel
Accessibility
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: status
- ARIA attributes: aria-label
- Keys handled: Enter, Space
- Respects the reduced motion setting
- Announces changes to screen readers