Unit Input

Unit Input is a copy-paste React component that stops height saved in the wrong unit 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/unit-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

StopsHeight saved in the wrong unit

Was this component page useful?

How do I install Unit Input?

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

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

How do I use Unit Input in React?

unit-input-usage.tsx
import { UnitInput } from "@/components/ui/unit-input"

<UnitInput label="Height" preset="height" defaultValue="70" />

What input mistakes does Unit Input catch?

  • Values outside the usual range for the unit but inside another's
  • Feet-and-inches notation (5'9", 5 ft 9 in, 5.9)
  • Body temperature in the wrong scale
  • Conversion rounded to the target unit's precision

What props does Unit Input accept?

UnitInput props
PropTypeDefault
label* (required)

Visible label.

string—
hint

Helper text shown under the field while there is nothing to warn about.

string—
preset* (required)

A built-in preset or your own units and plausible ranges.

keyof typeof UNIT_PRESETS | UnitPreset—
ranges

Override plausible ranges per unit id, e.g. `{ cm: [45, 120] }` for children.

Record<string, [number, number]>—
value

Controlled text of the number.

string—
defaultValue

Initial text when uncontrolled.

string""
onValueChange

Called with the number's text on every change.

(value: string) => void—
unit

Controlled unit id.

string—
defaultUnit

Unit selected initially; defaults to the first unit.

string—
onUnitChange

Called when the unit changes, including from a one-tap switch.

(unit: string) => void—
onMeasurementChange

Called with the number, its unit and the value in the preset's base unit, or null.

(measurement: { value: number; unit: string; base: number } | null) => void—
delay

Pause in ms before warnings appear while typing. Leaving the field shows them at once.

number700
keepLabel

Accessible label of the button that keeps the value as typed.

string"Keep it as typed"
messages

Override any other visible string.

Partial<typeof UNIT_INPUT_MESSAGES>—

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

How is Unit Input accessible?

  • Visible <label>; unit picker has an aria-label
  • aria-invalid with suggestions in a polite live region via aria-describedby
  • Keep-as-typed dismiss has an aria-label

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

What are the limitations and server boundaries?

  • Plausibility ranges are presets you can override; unusual real values can be flagged
  • Converts between the units in the preset only

What expensive mistakes does Unit Input stop?

Height saved in the wrong unit

Also known as

units · unit converter · cm inches · kg lbs · height · weight · temperature · measurements

Field type

What dependencies does Unit Input require?

Unit Input facts & technical specifications

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

What form validation mistake does Unit Input catch?

Unit Input prevents height saved in the wrong unit. Notices when a number makes far more sense in another unit (70 cm is likely inches) and offers a one-tap conversion. Catches: Values outside the usual range for the unit but inside another's, Feet-and-inches notation (5'9", 5 ft 9 in, 5.9), Body temperature in the wrong scale, Conversion rounded to the target unit's precision. Limitation: validate unit-input schemas on backend.

How do I install unit-input with shadcn?

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

What props customize Unit Input?

Unit Input accepts `label`, `hint`, `preset`, `ranges`, `value`. Configures units, unit converter, cm inches behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of unit-input?

Plausibility ranges are presets you can override; unusual real values can be flagged. Converts between the units in the preset only Server requirement: backend verification for unit-input.

How does Unit Input meet accessibility guidelines?

Visible <label>; unit picker has an aria-label. aria-invalid with suggestions in a polite live region via aria-describedby. Keep-as-typed dismiss has an aria-label. Minimizes errors: cm vs inches, fahrenheit celsius wrong.

Which components pair with Unit Input?