# Hold to Confirm

> A button that fills while held, for actions that deserve a moment's thought.

Source: https://www.honestui.com/docs/animated/hold-to-confirm

```tsx
"use client";

import { useState } from "react";
import { HoldToConfirm } from "@/registry/default/animated/hold-to-confirm";

export function HoldToConfirmDemo() {
  const [deleted, setDeleted] = useState(0);

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <div className="rounded-xl border border-border bg-card p-5">
        <p className="text-sm font-medium text-foreground">Delete project</p>
        <p className="mt-1 text-[13px] leading-5 text-muted-foreground">
          Removes the project, its deployments, and 14 environment variables. This cannot be undone.
        </p>
        <div className="mt-4 flex items-center justify-between gap-3">
          <span className="text-xs text-muted-foreground tabular-nums">
            {deleted > 0 ? `Deleted ${deleted} ${deleted === 1 ? "time" : "times"} in this demo` : "Press and hold"}
          </span>
          <HoldToConfirm
            variant="destructive"
            holdLabel="Keep holding…"
            confirmedLabel="Deleted"
            onConfirm={() => setDeleted((count) => count + 1)}
          >
            Delete project
          </HoldToConfirm>
        </div>
      </div>
      <div className="flex flex-wrap items-center justify-center gap-3">
        <HoldToConfirm size="sm" confirmedLabel="Archived">
          Archive
        </HoldToConfirm>
        <HoldToConfirm duration={2000} holdLabel="Publishing…" confirmedLabel="Published">
          Publish to production
        </HoldToConfirm>
      </div>
    </div>
  );
}

```

## Overview [#overview]

Hold to Confirm replaces a confirmation dialog for destructive or costly actions. People press and hold the button, a fill sweeps across it at a steady pace, and the action runs only when the fill reaches the end. Letting go early rewinds the fill, so nothing happens by accident and there is no extra dialog to dismiss.

The fill is a second copy of the label on a solid surface, revealed from the left, so the text changes color exactly where the fill passes it. The fill is linear on purpose: it is a timer, and an eased fill would misreport how much time is left. All labels share one grid cell, so the button keeps the width of the longest label and never resizes under the pointer.

## Installation [#installation]

<CliBlock commands="[&#x22;hold-to-confirm&#x22;]" />

## Usage [#usage]

```tsx
import { HoldToConfirm } from "@/components/animated/hold-to-confirm"

<HoldToConfirm
  variant="destructive"
  holdLabel="Keep holding…"
  confirmedLabel="Deleted"
  onConfirm={deleteProject}
>
  Delete project
</HoldToConfirm>
```

Set `resetAfter={false}` to keep the confirmed state, for example while the request is in flight and the button is about to unmount:

```tsx
<HoldToConfirm resetAfter={false} confirmedLabel="Publishing" onConfirm={publish}>
  Publish to production
</HoldToConfirm>
```

## Accessibility [#accessibility]

The control is a native `button`. A visually hidden hint, "Press and hold to confirm" by default, is attached with `aria-describedby`, so screen readers explain the interaction when the button is focused. Change it with `hint` when your label needs a different instruction.

Holding Space or Enter works the same as holding the pointer. A quick click or key press does nothing, and keyboard auto-repeat does not restart the hold. Moving the pointer off the button, losing focus, or disabling the button mid-hold lets go. When the hold completes, the confirmed label is announced through a polite live region; pass `confirmedMessage` when the label is not plain text or needs more detail.

With reduced motion enabled, the fill still runs for the full duration, since it shows how long is left, but it snaps back instead of rewinding and labels change with a short fade instead of a blur. Devices that support vibration give a light tap on confirm.

Use the button for actions that are serious but routine. For actions that cannot be undone and affect other people, a dialog that names what will be lost is still the clearer choice.

## API Reference [#api-reference]


  ### `children`

type: `ReactNode`

The action label, such as "Delete project".

  ### `holdLabel`

type: `ReactNode`

Label shown while the button is held. Defaults to the action label.

  ### `confirmedLabel`

type: `ReactNode` · default: `&#x22;Done&#x22;`

Label shown, with a check, once the hold completes.

  ### `duration`

type: `number` · default: `1200`

Milliseconds the button must be held.

  ### `onConfirm`



void">
    Called once when the hold completes.

  ### `variant`

type: `&#x22;default&#x22; | &#x22;destructive&#x22;` · default: `&#x22;default&#x22;`

Visual style. Use 

    `destructive`

     for actions that remove or cancel something.

  ### `size`

type: `&#x22;sm&#x22; | &#x22;md&#x22; | &#x22;lg&#x22;` · default: `&#x22;md&#x22;`

Button height and padding.

  ### `resetAfter`

type: `number | false` · default: `1600`

Milliseconds the confirmed state stays before the button resets. 

    `false`

     keeps it confirmed.

  ### `hint`

type: `string` · default: `&#x22;Press and hold to confirm&#x22;`

Hidden instruction read with the button.

  ### `confirmedMessage`

type: `string`

Announced on confirm. Defaults to the confirmed label when it is text.

  ### `disabled`

type: `boolean` · default: `false`

Disables the button and lets go of a hold in progress.

  ### `className`

type: `string`

Class for the button.


Other `button` attributes, such as `aria-label` or `form`, are passed through.
