Hold Button

HoldButton is a shadcn Button wrapper that runs an action only after the user presses and holds it for a set duration (default 1200 ms). It is meant for hard-to-undo actions such as deletes and resets, and releasing early cancels the action.

Hold Button
LIVE · running in a sandboxed iframe
Installed with shadcn add · 2 workarounds · theme from registry.json
  • applied the registry's theme (tokens, fonts and CSS from the registry preview settings)
  • installed base item https://ui.balick.me/r/theme.json (registry preview settings)
See how it was built

Installation

pnpm dlx shadcn@latest add @balick/hold-button

Requires @balick in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { HoldButton } from "@/components/ui/hold-button"<HoldButton onConfirm={handleDelete}>Delete</HoldButton>
  • Destructive or irreversible actions such as deleting a project, account, or dataset, where a single click is too risky.
  • Actions that need a deliberate gesture to prevent accidental triggering, such as resetting settings or discarding unsaved work.
  • Situations where you want visible progress feedback during a confirmation, instead of a separate confirmation dialog.
  • Not suitable for quick, reversible actions like saving or toggling, since a hold adds friction and is not discoverable on touch-only devices.

Examples

Delete a project with a longer hold

Uses the default destructive variant and increases the hold duration to 2 seconds to reduce accidental confirmations.

delete-a-project-with-a-longer-hold.tsx
import { HoldButton } from "@/components/ui/hold-button"export function DeleteProjectButton({ onDelete }: { onDelete: () => void }) {  return (    <HoldButton onConfirm={onDelete} duration={2000}>      Delete project    </HoldButton>  )}

Reset settings with an outline variant

Passes Button props such as variant and size through to the underlying button.

reset-settings-with-an-outline-variant.tsx
import { HoldButton } from "@/components/ui/hold-button"export function ResetSettingsButton({ onReset }: { onReset: () => void }) {  return (    <HoldButton variant="outline" size="sm" onConfirm={onReset}>      Reset settings    </HoldButton>  )}

Disabled state while a request is running

The disabled prop is forwarded to Button, so a disabled HoldButton cannot be held.

disabled-state-while-a-request-is-running.tsx
import { HoldButton } from "@/components/ui/hold-button"export function DiscardDraftButton({  onDiscard,  saving,}: {  onDiscard: () => void  saving: boolean}) {  return (    <HoldButton onConfirm={onDiscard} disabled={saving} className="w-full">      Discard draft    </HoldButton>  )}

API reference

PropTypeDefaultDescription
onConfirm() => void—Called once the button has been held for the full duration. Required.
durationnumber1200How long to hold, in milliseconds.
variantButton variant ("default" | "destructive" | "outline" | "secondary" | "ghost" | "link")"destructive"Visual variant forwarded to Button. Overrides the destructive default when set.
classNamestring—Additional classes merged with the base classes (relative, cursor-pointer, overflow-hidden, select-none) via cn.
childrenReact.ReactNode—Label or content rendered inside the button above the progress fill.
...restOmit<React.ComponentProps<typeof Button>, "onClick">—All other Button props (such as size, disabled, asChild-free button attributes) are forwarded. onClick is omitted, and pointer, keyboard, blur and context-menu handlers are owned by the hold logic and override any passed in.

Accessibility

  • The button renders a native button with type="button", so it is focusable and operable with the keyboard.
  • Space or Enter pressed and held starts the hold, and releasing either key cancels it. Auto-repeat keydown events are ignored, so holding a key does not restart the timer.
  • A visually hidden suffix ", hold to confirm" is appended to the accessible name, so screen reader users hear that a hold is required. The suffix is fixed English text and is not localized, so translate it if your UI is not in English.
  • The progress fill is aria-hidden and conveys no information to assistive technology. Consider exposing progress separately if the hold is long.
  • Activation by click or by assistive technology's virtual click does not trigger onConfirm, because onClick is omitted. Users of switch-style or click-only interfaces cannot complete the action without a press-and-hold gesture. Provide an alternative path for those users when the action is critical.
  • Pointer leaving the button, losing focus, pointer cancel, or a context menu all cancel the hold, which prevents accidental confirmation.
  • Disabled state is forwarded to Button, so a disabled HoldButton cannot be held.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Hold Button" component (balick/hold-button) from its shadcn registry.1. Install it with: npx shadcn@latest add @balick/hold-button2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: onConfirm, duration, variant, className, children, ...rest.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { HoldButton } from "@/components/ui/hold-button"<HoldButton onConfirm={handleDelete}>Delete</HoldButton>```

Files & dependencies

  • registry/balick/ui/hold-button.tsx
registryDependenciesbutton

Looks similar, elsewhere