Coupon Input

Coupon Input is a copy-paste React component that stops valid coupon code rejected 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/coupon-input
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

StopsValid coupon code rejected

Was this component page useful?

How do I install Coupon Input?

pnpm dlx shadcn@latest add @bollard/coupon-input

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

How do I use Coupon Input in React?

coupon-input-usage.tsx
import { CouponInput, type CouponResult } from "@/components/ui/coupon-input"

<CouponInput
  onApply={check}
  defaultCode="save1OO"
  knownCodes={["SAVE100", "WELCOME20", "FEST10"]}
  timeZone="Asia/Kolkata"
/>

What input mistakes does Coupon Input catch?

  • Pasted spaces, hidden characters and wrong case
  • Look-alike characters (O/0, I/1) against known codes
  • The specific reason a code was rejected, such as the amount still needed
  • A capped discount, shown as the real saving
  • A worse code replacing a better one

What props does Coupon Input accept?

CouponInput props
PropTypeDefault
onApply* (required)

Checks a cleaned code against the cart. May return a Promise; a rejection shows a retry.

(code: string) => CouponResult | Promise<CouponResult>—
value

The applied code, controlled. `null` when none.

Applied | null—
defaultValue

The applied code when uncontrolled.

Applied | nullnull
onValueChange

Called when a code is applied or removed.

(value: Applied | null) => void—
knownCodes

Public codes (banners, emails) to compare a not-found code against for look-alike typos.

string[][]
defaultCode

A code to check straight away, e.g. from a `?coupon=` link or a "copy code" banner.

string—
caseSensitive

Keep letter case as typed. Most shops treat codes as case-insensitive.

booleanfalse
guardDowngrade

Ask before replacing an applied code with one that saves less. Turn off when codes stack.

booleantrue
currency

ISO 4217 code for savings and minimums.

string"INR"
locale

BCP 47 locale for money and dates.

string"en-IN"
timeZone

Time zone for expiry dates.

string—
messages

Reword or translate any sentence.

Partial<typeof COUPON_INPUT_MESSAGES>—

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

How is Coupon Input accessible?

  • Visible <label>; aria-invalid and aria-describedby to the status
  • Enter applies; suggestion and remove buttons have aria-labels
  • Focus returns to the input after actions

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: Validate and price coupons on the server; never trust a discount computed in the browser.

  • Look-alike suggestions need knownCodes; otherwise it only cleans
  • Validity and rejection reasons come from your onApply

What expensive mistakes does Coupon Input stop?

Valid coupon code rejected

Also known as

coupon · promo code · discount code · voucher · offer code · checkout · cart · apply code

Field type

What dependencies does Coupon Input require?

Coupon Input facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameCoupon Input
Registry identifier@bollard/coupon-input
Install commandnpx shadcn@latest add @bollard/coupon-input
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-10-16
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 Coupon Input

How does Coupon Input prevent financial transaction errors?

Coupon Input prevents valid coupon code rejected. Blocks Pasted spaces, hidden characters and wrong case, Look-alike characters (O/0, I/1) against known codes, The specific reason a code was rejected, such as the amount still needed, A capped discount, shown as the real saving, A worse code replacing a better one before processing. Limitation: apply idempotency keys for coupon-input.

How do I install coupon-input with shadcn?

Run `npx shadcn@latest add @bollard/coupon-input`. Sources added: registry/default/coupon-input/coupon-input.tsx, registry/default/coupon-input/coupon.ts. Package requirements: lucide-react.

What props customize Coupon Input?

Coupon Input accepts `onApply`, `value`, `defaultValue`, `onValueChange`, `knownCodes`. Configures coupon, promo code, discount code behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of coupon-input?

Look-alike suggestions need knownCodes; otherwise it only cleans. Validity and rejection reasons come from your onApply Server requirement: Validate and price coupons on the server; never trust a discount computed in the browser.

How does Coupon Input meet accessibility guidelines?

Visible <label>; aria-invalid and aria-describedby to the status. Enter applies; suggestion and remove buttons have aria-labels. Focus returns to the input after actions. Minimizes errors: coupon code not working, promo code invalid.

Which components pair with Coupon Input?