Percent Input

Percent Input is a copy-paste React component that stops rate entered 100 times too small 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/percent-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

StopsRate entered 100 times too small

Was this component page useful?

How do I install Percent Input?

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

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

How do I use Percent Input in React?

percent-input-usage.tsx
import { PercentInput } from "@/components/ui/percent-input"

<PercentInput label="Tip" defaultValue={0.15} base={2000} currency="INR" />

What input mistakes does Percent Input catch?

  • Fraction typed instead of percent (0.15 for 15%)
  • Tiny basis-point values (0.25 bps for 25)
  • Over max or under min, with a dropped-zero fix (150 → 15)
  • Money readback against a base amount

What props does Percent Input accept?

PercentInput props
PropTypeDefault
label

Visible label.

string"Percentage"
value

Controlled value, in `valueFormat`. `null` means empty.

number | null—
defaultValue

Initial value when uncontrolled.

number | nullnull
onValueChange

Called with the value in `valueFormat`, or `null` when empty or unreadable.

(value: number | null) => void—
valueFormat

How values go in and out: `percent` (15 means 15%) or `fraction` (0.15 means 15%).

"percent" | "fraction""percent"
min

Lowest allowed percent.

number0
max

Highest allowed percent. Set higher for growth rates or markups.

number100
likelyMin

Positive values below this look like a decimal typed for a percent (0.15 for 15%). 0 turns it off.

number1
basisPoints

Show a % / bps switch. Switching converts the typed number, so the amount never changes meaning.

booleanfalse
defaultUnit

Unit the field starts in when `basisPoints` is on.

PercentUnit"percent"
base

Amount the percent applies to, for the readback ("15% of ₹2,000 = ₹300").

number—
currency

ISO 4217 currency of `base`. Leave out for a plain number.

string—
locale

BCP 47 locale for number formatting.

string"en-IN"
fractionMessage

Message when a fraction was typed for a percent.

(typed: string, fix: string) => string(typed, fix) => `${typed} is under 1%. Did you mean ${fix}?`
tinyBpsMessage

Message when a tiny basis-point value was typed.

(typed: string, fix: string) => string(typed, fix) => `${typed} is a tiny fraction of a percent…
overMessage

Message when the value is above max.

(max: string) => string(limit) => `Can't be more than ${limit}.`
underMessage

Message when the value is below min.

(min: string) => string(limit) => `Can't be less than ${limit}.`
fixLabel

Fix button text; receives the fixed value with its unit, e.g. "15%".

(fix: string) => string(fix) => `Use ${fix}`
decimalText

Readback without a base; receives the percent and the same value as a decimal.

(percent: string, decimal: string) => string(percent, decimal) => `${percent} = ${decimal} as a decimal`

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

How is Percent Input accessible?

  • Visible label; input has aria-invalid on error and is described by a polite status
  • Errors use role=alert
  • Unit switch is a labelled group of aria-pressed buttons

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

What are the limitations and server boundaries?

  • "Likely" ranges are heuristics; set likelyMin, min and max for your domain
  • Locale defaults to en-IN; pass locale and currency for other markets

What expensive mistakes does Percent Input stop?

Rate entered 100 times too small

Also known as

percent · percentage · rate · discount · interest rate · commission · gst rate · bps

Field type

What dependencies does Percent Input require?

Percent Input facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component namePercent Input
Registry identifier@bollard/percent-input
Install commandnpx shadcn@latest add @bollard/percent-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 Percent Input

How does Percent Input prevent financial transaction errors?

Percent Input prevents rate entered 100 times too small. Blocks Fraction typed instead of percent (0.15 for 15%), Tiny basis-point values (0.25 bps for 25), Over max or under min, with a dropped-zero fix (150 → 15), Money readback against a base amount before processing. Limitation: apply idempotency keys for percent-input.

How do I install percent-input with shadcn?

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

What props customize Percent Input?

Percent Input accepts `label`, `value`, `defaultValue`, `onValueChange`, `valueFormat`. Configures percent, percentage, rate behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of percent-input?

"Likely" ranges are heuristics; set likelyMin, min and max for your domain. Locale defaults to en-IN; pass locale and currency for other markets Server requirement: backend verification for percent-input.

How does Percent Input meet accessibility guidelines?

Visible label; input has aria-invalid on error and is described by a polite status. Errors use role=alert. Unit switch is a labelled group of aria-pressed buttons. Minimizes errors: 0.15 vs 15 percent, basis points confusion.

Which components pair with Percent Input?