Hold To Confirm

A destructive-action guard button that fills a colored bar while the user presses and holds it, and only fires onConfirm once the hold completes. It supports pointer, Space, and Enter input.

Hold To Confirm
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 @glint-ui/hold-to-confirm

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

Usage

usage.tsx
import { HoldToConfirm } from '@/components/ui/hold-to-confirm'<HoldToConfirm onConfirm={() => console.log('confirmed')} />
  • Guarding irreversible actions such as deleting a record, revoking access, or wiping data, where a single click is too easy to trigger by accident.
  • Replacing a confirmation dialog with an inline, one-gesture confirmation for quick destructive actions in lists or cards.
  • Providing a deliberate, visible progress cue so users know the action is in progress and can cancel by releasing early.
  • Keyboard-accessible destructive buttons where Space or Enter must be held rather than tapped.

Examples

Delete item

Hold-to-delete button wired to a delete handler for a list row.

delete-item.tsx
import { HoldToConfirm } from '@/components/ui/hold-to-confirm'export function DeleteItemAction({ id, onDelete }: { id: string; onDelete: (id: string) => void }) {  return <HoldToConfirm label='Hold to delete' confirmedLabel='Deleted' onConfirm={() => onDelete(id)} />}

Custom duration and color

A longer hold with a warmer fill color for a more severe action.

custom-duration-and-color.tsx
import { HoldToConfirm } from '@/components/ui/hold-to-confirm'export function RevokeAccessAction({ onRevoke }: { onRevoke: () => void }) {  return <HoldToConfirm duration={3000} color='#f97316' label='Hold to revoke' confirmedLabel='Revoked' onConfirm={onRevoke} />}

Full-width in a danger zone

Using className to stretch the button inside a settings danger panel.

full-width-in-a-danger-zone.tsx
import { HoldToConfirm } from '@/components/ui/hold-to-confirm'export function DangerZone({ onReset }: { onReset: () => void }) {  return (    <section className='rounded-lg border p-4'>      <h3 className='text-sm font-semibold'>Reset workspace</h3>      <HoldToConfirm className='mt-3 w-full' label='Hold to reset' confirmedLabel='Workspace reset' duration={2500} onConfirm={onReset} />    </section>  )}

Trigger a mutation with state

Reacting to the confirmed state by disabling related UI in the parent.

trigger-a-mutation-with-state.tsx
import { useState } from 'react'import { HoldToConfirm } from '@/components/ui/hold-to-confirm'export function ArchiveProject() {  const [archived, setArchived] = useState(false)  return (    <div className='flex items-center gap-3'>      <HoldToConfirm label='Hold to archive' confirmedLabel='Archived' onConfirm={() => setArchived(true)} />      {archived && <span className='text-sm text-muted-foreground'>Project archived</span>}    </div>  )}

API reference

PropTypeDefaultDescription
durationnumber1500Milliseconds the button must be held before onConfirm fires. Also sets the fill transition length while holding.
labelstring"Hold to delete"Text shown before the hold completes.
confirmedLabelstring"Deleted"Text shown after the hold completes, for about 2 seconds before resetting.
colorstring"#ef4444"CSS color used for the progress fill.
onConfirm() => void—Called once when the hold completes.
classNamestring—Additional classes appended to the button element.

Accessibility

  • Rendered as a native button with type="button", so it is focusable and keyboard-operable with Space and Enter.
  • Keyboard activation requires holding the key: keydown starts the timer, keyup cancels it, and auto-repeat (e.repeat) is ignored so holding does not restart the timer.
  • The default keydown/keyup handling calls preventDefault for Space and Enter, which suppresses the native click; the component does not fire a click-based action.
  • The progress fill is aria-hidden, so screen readers rely on the text label only; progress is not announced.
  • The label span has aria-live="polite", so the change from label to confirmedLabel is announced after completion.
  • Make label text describe the action clearly (for example, 'Hold to delete invoice'), because the visible text is the only accessible name and no instruction is exposed beyond it.
  • Sighted-only progress cues: consider providing an alternative confirmation path for users who cannot sustain a press.
  • The component does not spread extra HTML attributes onto the button, so aria-* attributes cannot be passed as props.

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 Confirm" component (glint-ui/hold-to-confirm) from its shadcn registry.1. Install it with: npx shadcn@latest add @glint-ui/hold-to-confirm2. 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: duration, label, confirmedLabel, color, onConfirm, className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { HoldToConfirm } from '@/components/ui/hold-to-confirm'<HoldToConfirm onConfirm={() => console.log('confirmed')} />```

Files & dependencies

  • registry/ui/hold-to-confirm.tsx

Looks similar, elsewhere