UI

Hold to confirm

Confirm a destructive action by holding instead of tapping.

import { HoldToConfirm } from '@uthereal/ui/hold-to-confirm'

Hold to confirm playground

Press and hold for 1.2s to confirm. With a keyboard, hold Space or Enter.
Loading interactive preview…

Overview

HoldToConfirm renders a native <button> that commits only after the user holds it for duration milliseconds. A clipped fill sweeps across the button on a linear timeline and flips the text and icon color at the exact fill edge. Releasing early rewinds the fill on a spring. Completing the hold morphs the label and icon into confirmedLabel with a drawn check mark.

Use HoldToConfirm for destructive or hard-to-undo actions when the consequence is already visible on screen. Use Dialog when users must read detailed consequences before confirming, and use Button for standard single-tap actions.

Usage

'use client'
import { HoldToConfirm } from '@uthereal/ui/hold-to-confirm'

export function DangerZone() {
  return (
    <HoldToConfirm
      label="Hold to delete project"
      confirmedLabel="Deleted"
      action="delete_project"
      onAction={(action) => console.log(action)}
    />
  )
}

Your application owns side effects and implements the named action in onAction. Pass onConfirm for a direct React callback, or control completion with confirmed and onConfirmedChange.

Examples

Use <SchemaPlayground /> above to inspect tone, size, duration, icon, recipe, and motion. The examples below show distinct action gravities, settled states, and controlled resets.

Action gravity and hold duration

Match duration, tone, icon, and confirmedLabel to the risk of the operation. Longer holds add friction to irreversible operations, while shorter holds guard reversible state changes.

Press and hold for 2s to confirm. With a keyboard, hold Space or Enter.
Press and hold for 0.8s to confirm. With a keyboard, hold Space or Enter.

Confirmed and disabled states

Set defaultConfirmed to start in the settled state with the drawn check mark and aria-disabled="true". Set disabled to block interaction and remove the button from the tab order.

Press and hold for 1.2s to confirm. With a keyboard, hold Space or Enter.Archived
Press and hold for 1.2s to confirm. With a keyboard, hold Space or Enter.

Controlled reset and hold status

Pass confirmed and onConfirmedChange to reset the button after a delay or decline a confirmation. Pass onHoldChange to display contextual hints while the hold is active.

'use client'
import { useState } from 'react'
import { HoldToConfirm } from '@uthereal/ui/hold-to-confirm'

export function ControlledReset() {
  const [confirmed, setConfirmed] = useState(false)
  const [holding, setHolding] = useState(false)

  return (
    <div>
      <HoldToConfirm
        label="Hold to revoke API key"
        confirmedLabel="Revoked"
        confirmed={confirmed}
        onConfirmedChange={setConfirmed}
        onHoldChange={setHolding}
      />
      {holding && <span>Keep holding to revoke.</span>}
      {confirmed && (
        <button type="button" onClick={() => setConfirmed(false)}>
          Reset
        </button>
      )}
    </div>
  )
}

Hold gesture mechanics

Gesture phaseBehavior
Press and holdCaptures the primary pointer and advances the fill linearly over the remaining hold time.
Quick re-pressResumes the fill from its current progress instead of restarting from zero.
Drag cancelKeeps holding while the pointer stays within 24px of the button bounds, then cancels and rewinds beyond 24px.
Early releaseStops the hold, releases press scale, and rewinds the fill on a zero-overshoot spring.
CompletionStops the hold, triggers a 12ms touch vibration when supported, enters the confirmed state, and fires onConfirm and onAction.
Controlled declineRewinds the fill when the parent keeps confirmed={false} after completion.
Mid-hold disableImmediately cancels an active hold and rewinds the fill if disabled turns true.

API reference

Serializable schema arguments and defaults come directly from holdToConfirmConfigSchema.

ArgumentType / defaultDescription
labelRequiredstring—The instruction and the action, e.g. "Hold to delete project". A verb with its object, sentence case.
confirmedLabelstringDefault: "Done"Shown once the hold completes, e.g. "Deleted". Announced politely when it appears.
holdingHintstring—Keyboard and hold-length hint for assistive technology; {seconds} is the hold length in seconds. Unset: "Press and hold for {seconds}s to confirm. With a keyboard, hold Space or Enter."
durationintegerDefault: 1200How long the button must be held to confirm, ms. 300–10,000.
iconIconName—Icon of the action while at rest, e.g. trash-2 for a deletion. Any name from the Icons page.
tonedanger | neutral | accentDefault: "danger"Fill role. danger is for an irreversible action (the default), neutral fills with ink, accent follows the theme accent.
sizexs | sm | md | lgDefault: "md"Height: 32, 36, 44, or 50 pixels, with 14px text at every size. Matches the dropdown trigger of the same size.
actionstring—Name of an action registered by your application. Sent to onAction once the hold completes.
defaultConfirmedbooleanDefault: falseInitial confirmed state. Edits do not reset a mounted instance; in compositions the stored state wins.
disabledbooleanDefault: falseUnavailable and removed from the tab order. A held fill releases and rewinds.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeHoldToConfirmTheme—Color mode, accent, and semantic tokens.
motionnone | subtle | expressiveDefault: "subtle"Fill, press and swap animation preset. System reduced-motion preferences take precedence.
motionOptionsHoldToConfirmMotionOptions—Press scale (omitted, it follows the width), and label swap duration (ms) and travel (px).
dirltr | rtl—Reading direction. Omit it to inherit the page direction.

React integration

PropPurpose
confirmed, onConfirmedChangeControlled confirmed state and change callback. Set confirmed back to false to reset the control.
onConfirm()Called once when the hold completes.
onAction(action)Called with the configured action name once the hold completes.
onHoldChange(holding)Reports when a hold starts (true) and ends (false), for external status hints.
renderIcon(name, context)Replaces the resting icon with custom decorative markup. The confirmed drawn check always stays.
presetComponent defaults overridden by explicit instance props.
tokens--ui-* CSS variables applied after the typed theme on the root button.
refRef to the rendered <button>.
className, styleAdded to the root button. style takes precedence over motion and theme tokens.
Native attributesForwarded button attributes including id, aria-*, data-*, name, and DOM event handlers.

Keyboard & accessibility

KeyInteraction
TabMoves focus to the button with a visible focus ring.
Space, Enter (hold)Starts or resumes the hold fill; key repeat events are ignored.
Space, Enter (release)Cancels an incomplete hold and rewinds the fill.
Tab or blur while holdingCancels an active hold and rewinds the fill.

Write label as an instruction and action ("Hold to delete project"). Before confirmation, aria-describedby links a visually hidden hint formatted with the active locale and duration (holdingHint supports a {seconds} placeholder). Once confirmed, aria-describedby clears, aria-disabled="true" keeps the button focusable without allowing repeat activation, aria-label updates to confirmedLabel, and a pre-mounted role="status" live region outside the button announces confirmedLabel politely.

The fill sweeps left-to-right in LTR and right-to-left in RTL (dir="rtl" or inherited page direction). Under forced-colors: active, the fill uses Highlight and HighlightText, disabled controls use GrayText, and focus outlines remain visible.

Motion and theming

The hold fill advances linearly over the remaining duration as product logic, even when motion is reduced or disabled. Releasing early rewinds the fill on spring.smooth (0.4s, zero bounce). Pressing scales the button by width (0.96 up to 48px, 0.985 above 220px, 0.97 between) on spring.snappy unless overridden by motionOptions.pressScale. Completing the hold springs the label container width via ResizeObserver on spring.morph, swaps the label with vertical rise and soft blur (motionOptions.labelDuration and motionOptions.labelOffset), and draws the check stroke over 480ms after an 80ms delay.

motion="none" removes press scale, spring rewinds, width morphs, and transitions, swapping states immediately. prefers-reduced-motion: reduce removes press scale, travel, blur, and springs while keeping a 120ms opacity crossfade for label and icon swaps.

theme accepts mode, accent, and tokens from the core and control groups plus borderStrong and toneForeground. UtherealProvider supplies application-wide defaults.

Composition

In agent compositions, HoldToConfirm is a leaf component. Register its action on the host; the handler receives { componentId }. Confirmed state persists at /components/instance-<id>/confirmed, starting from defaultConfirmed (false by default) and preserved across agent edits. See Building with agents.

{
  "type": "HoldToConfirm",
  "props": {
    "label": "Hold to delete project",
    "confirmedLabel": "Deleted",
    "duration": 1500,
    "tone": "danger",
    "action": "delete_project"
  },
  "children": []
}

On this page