Cooldown Button

Cooldown Button is a copy-paste React component that stops resend tapped again and again before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/cooldown-button
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsResend tapped again and again

Was this component page useful?

How do I install Cooldown Button?

pnpm dlx shadcn@latest add @bollard/cooldown-button

The files land in your project. They're yours to edit.

How do I use Cooldown Button in React?

cooldown-button-usage.tsx
import { CooldownButton, clearCooldown } from "@/components/ui/cooldown-button"

<CooldownButton
  key={run}
  id={ID}
  startCoolingDown
  cooldowns={[10, 20, 40]}
  maxAttempts={4}
  reason="SMS can take up to a minute to arrive."
  onAction={() =>
    new Promise<void>((resolve) =>
      setTimeout(() => {
        setSent((n) => n + 1)
        resolve()
      }, 600),
    )
  }
>
  Resend code
</CooldownButton>

What input mistakes does Cooldown Button catch?

  • Repeated taps on resend or retry, with a growing wait
  • Unclear waiting, by showing a countdown and the reason
  • Running out of attempts, with a clear locked message
  • Clicks before hydration, by staying inert until the saved state is restored

What props does Cooldown Button accept?

CooldownButton props
PropTypeDefault
id* (required)

Stable key for this action ("resend-otp:+91…"). The cooldown is stored under it for the tab's session.

string—
onAction* (required)

Runs on click. Return a promise; a rejection doesn't count as an attempt.

() => void | Promise<void>—
cooldowns

Seconds to wait after each attempt. The last value repeats for later attempts.

number[]DEFAULT_COOLDOWNS
maxAttempts

Attempts allowed before the button locks for the session.

number5
startCoolingDown

Treat mount as the first attempt (the code was sent when the page opened).

booleanfalse
variant

Visual style of the button.

keyof typeof variants"outline"
size

Size of the button.

keyof typeof sizes"default"
waitingLabel

Label while cooling down, given the remaining time ("0:42").

(remaining: string) => React.ReactNode(remaining) => `Resend in ${remaining}`
pendingLabel

Label while `onAction` is running.

React.ReactNode"Sending…"
reason

Why the user has to wait, shown under the button during the cooldown.

React.ReactNode"We just sent it. Give it a moment to arrive."
attemptsLabel

Attempts left, shown once the button is ready again or when few are left.

(left: number, max: number) => React.ReactNode(left, max) => `${left} of ${max} tries left.`
readyAnnouncement

Read to screen readers when the cooldown ends.

string"You can try again now."
exhaustedMessage

Shown once every attempt is used.

React.ReactNode"You've reached the limit for this session. Contact suppo…
errorMessage

Fallback when `onAction` rejects without an Error message.

string"That didn't go through. Try again."
className

Class for the wrapper that holds the button and its hint.

string—

* required. Also accepts the native props of <button> (className, aria-*, data-*…), passed through to it.

How is Cooldown Button accessible?

  • Stays focusable while waiting (aria-disabled instead of disabled)
  • aria-busy while pending and aria-describedby to the reason
  • Becoming ready is announced in an aria-live="polite" region
  • Errors and the exhausted message use role="alert"

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Enforce rate limits and attempt counts on the server (per account and IP), and make paid actions idempotent.

  • UI only: a new tab, another device or cleared storage bypasses the cooldown
  • It reduces accidental repeats; it does not rate-limit or prevent double charges on its own

What expensive mistakes does Cooldown Button stop?

Resend tapped again and again

Also known as

resend otp · resend code · otp · rate limit · countdown timer · sms · magic link · throttle

Field type

What dependencies does Cooldown Button require?

Cooldown Button facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameCooldown Button
Registry identifier@bollard/cooldown-button
Install commandnpx shadcn@latest add @bollard/cooldown-button
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-11-15
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Cooldown Button

How does Cooldown Button validate Indian financial identifiers?

Cooldown Button stops resend tapped again and again. Complies with national standards for Repeated taps on resend or retry, with a growing wait, Unclear waiting, by showing a countdown and the reason, Running out of attempts, with a clear locked message, Clicks before hydration, by staying inert until the saved state is restored. Limitation: verify cooldown-button with issuer gateway.

How do I install cooldown-button with shadcn?

Run `npx shadcn@latest add @bollard/cooldown-button`. Sources added: registry/default/cooldown-button/cooldown-button.tsx. Package requirements: lucide-react.

What props customize Cooldown Button?

Cooldown Button accepts `id`, `onAction`, `cooldowns`, `maxAttempts`, `startCoolingDown`. Configures resend otp, resend code, otp behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of cooldown-button?

UI only: a new tab, another device or cleared storage bypasses the cooldown. It reduces accidental repeats; it does not rate-limit or prevent double charges on its own Server requirement: Enforce rate limits and attempt counts on the server (per account and IP), and make paid actions idempotent.

How does Cooldown Button meet accessibility guidelines?

Stays focusable while waiting (aria-disabled instead of disabled). aria-busy while pending and aria-describedby to the reason. Becoming ready is announced in an aria-live="polite" region. Errors and the exhausted message use role="alert". Minimizes errors: resend otp spam, user keeps clicking resend.

Which components pair with Cooldown Button?