Hold Action Button

Hold to confirm while a liquid fill rises, or let go early to cancel.

Preview

"use client";

import { useState } from "react";
import { HoldActionButton } from "@/components/motion/hold-action-button";

export function HoldActionButtonPreview() {
  const [confirmed, setConfirmed] = useState(false);

  return (
    <div className="flex flex-col items-center justify-center gap-3">
      <HoldActionButton
        onHoldComplete={() => {
          setConfirmed(true);
          window.setTimeout(() => setConfirmed(false), 1800);
        }}
      >
        Hold for vertical fill
      </HoldActionButton>
      <HoldActionButton
        type="horizontal"
        onHoldComplete={() => {
          setConfirmed(true);
          window.setTimeout(() => setConfirmed(false), 1800);
        }}
      >
        Hold for horizontal fill
      </HoldActionButton>
      <p className="h-4 text-xs text-muted-foreground" aria-live="polite">
        {confirmed ? "Action confirmed" : "Release early to cancel"}
      </p>
    </div>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/hold-action-button

API Reference

className?
string

Classes merged onto the root element.

Default—
labels?
Partial<{ holding: string; complete: string; }>

Override any built-in string.

Default—
type?
"vertical" | "horizontal"

Fill rises from the bottom or sweeps in from the left. Default: "vertical"

Defaultvertical
labelClassName?
string

Classes merged onto the label wrapper.

Default—
holdingLabel?
ReactNode

Label shown while the button is held. Default: "Keep holding"

Default—
completeLabel?
ReactNode

Label shown once the hold completes. Default: "Done"

Default—
holdDuration?
number

How long the button must be held to complete (ms). Default: 1600

Default1600
onHoldComplete?
(() => void)

Called once when the fill finishes while still held.

Default—
fillClassName?
string

Classes merged onto the fill layer, e.g. to change its color.

Default—

More in Animated CTA Buttons

Updated