Hold to delete

A destructive-action button that fills with red over 2 seconds while the user holds it, then fires onDelete and morphs into a "Deleted" state with an animated bin and checkmark. Releasing early snaps the fill back within 200ms.

componentbuttonsregistry-item.json
Hold to delete
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @xevrion/hold-to-delete

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

Usage

usage.tsx
import { HoldToDelete } from "@/components/hold-to-delete";export function DeleteButton() {  return <HoldToDelete onDelete={() => console.log("deleted")} />;}
  • Destructive actions (delete item, remove account, discard draft) where an accidental single click must not cause data loss.
  • Replacing a confirmation dialog with an in-place, deliberate gesture for list rows or cards.
  • Places where a playful, tactile micro-interaction is appropriate for a high-stakes button.
  • Avoid for frequent or reversible actions, or for touch-only audiences who may not discover press-and-hold.

Examples

Delete a list item

Calls a handler that removes the row once the hold completes.

delete-a-list-item.tsx
import { HoldToDelete } from "@/components/hold-to-delete";type Props = { id: string; onRemove: (id: string) => void };export function TodoRow({ id, onRemove }: Props) {  return (    <div className="flex items-center justify-between rounded-lg border p-3">      <span className="text-sm">Buy milk</span>      <HoldToDelete onDelete={() => onRemove(id)} />    </div>  );}

Full-width danger zone

Stretches the button across a settings panel using className.

full-width-danger-zone.tsx
import { HoldToDelete } from "@/components/hold-to-delete";export function DangerZone() {  return (    <section className="space-y-2 rounded-xl border border-destructive/40 p-4">      <h3 className="text-sm font-semibold">Delete project</h3>      <p className="text-sm text-muted-foreground">This cannot be undone.</p>      <HoldToDelete        className="w-full"        onDelete={() => {          fetch("/api/project", { method: "DELETE" });        }}      />    </section>  );}

Default demo

The file exports a demo component with no props.

default-demo.tsx
import { HoldToDeleteDemo } from "@/components/hold-to-delete";export default function Page() {  return <HoldToDeleteDemo />;}

API reference

PropTypeDefaultDescription
onDelete() => void—Called once when the hold completes (the fill finishes its transition to the full width). Not called if the user releases early.
classNamestring—Additional Tailwind classes merged onto the button via cn(), for example to set width or margin.

Accessibility

  • Renders a native button with type="button", so it is focusable and activatable by keyboard.
  • Space and Enter start the hold on keydown (repeat events ignored); keyup releases it. Holding for the full duration is required, so keyboard users must keep the key down for about 2 seconds.
  • The red fill layer and the bin/check icons are aria-hidden, so screen readers rely on the visible label text.
  • A visually hidden aria-live="polite" region announces "Deleted" when the state becomes done.
  • The gulp keyframe and bin lid motion are disabled under prefers-reduced-motion via motion-reduce classes and a media query; the fill's clip-path transition is not disabled in the source.
  • The source sets no explicit focus-visible ring; consumers should add one through className if needed.
  • Context menu is suppressed on the button, which may surprise users who expect right-click menus.

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 to delete" component (xevrion/hold-to-delete) from its shadcn registry.1. Install it with: npx shadcn@latest add @xevrion/hold-to-delete2. 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: onDelete, className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { HoldToDelete } from "@/components/hold-to-delete";export function DeleteButton() {  return <HoldToDelete onDelete={() => console.log("deleted")} />;}```

Files & dependencies

  • components/hold-to-delete.tsx
dependenciesmotion
registryDependenciesutils

Looks similar, elsewhere