Skip to Content
zjkm-ui
Components

Hold to Confirm

A button you press and hold to confirm.

Press and hold

Props
1200ms
<HoldToConfirm onConfirm={remove}>
  Hold to delete
</HoldToConfirm>

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/hold-to-confirm.json
import { 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

PropTypeDefaultDescription
childrenReactNodeThe label.
onConfirm() => voidCalled after a full hold.
durationnumber1200Milliseconds to hold.
colorstring"#b91c1c"Button colour. Keep it dark enough for white text.
classNamestringClasses for the button.

With reduced motion, the button shows it's being held without the fill sweeping across.

On this page