Dimension Input

Labels each side of a size, fills all three from a pasted "16 x 12 x 8 in" and catches wrong units or an extra digit, so the wrong package size doesn't ship.

StopsWrong package size ships

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/dimension-input.json

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

Usage

dimension-input-usage.tsx
import { DimensionInput, type DimensionValue } from "@/components/ui/dimension-input"

<DimensionInput label="Cabin bag size" category="carry-on" value={dims} onValueChange={setDims} />

What it catches

  • The wrong unit for the item category (cm entered as inches)
  • A side with an extra digit
  • Sides entered in an unexpected order
  • Pasted sizes like "16 x 12 x 8 in", split into fields
  • Courier volumetric weight, using your divisor

Props

DimensionInput props
PropTypeDefault
label

Group label.

string"Dimensions"
value

Controlled value.

DimensionValue—
defaultValue

Initial value when uncontrolled.

DimensionValue{ w: "", h: "", d: "", unit: "cm" }
onValueChange

Called on every change, including a pasted "40 x 30 x 20 cm" that fills all three sides.

(value: DimensionValue) => void—
category

What is being measured, to judge sizes and side order. A built-in key or your own ranges.

keyof typeof DIMENSION_CATEGORIES | DimensionCategory—
units

Units offered in the picker.

DimensionUnit[]["cm", "mm", "m", "in", "ft"]
axisLabels

Names for each side.

Record<Axis, string>{ w: "Width", h: "Height", d: "Depth" }
volumetricDivisor

Courier divisor in cm³/kg for the volumetric weight readback (5000 for express couriers); null hides it.

number | null5000
volumetricLabel

Text after the volumetric weight.

string"volumetric"
unitLabel

Label of the unit picker.

string"Unit"
messages

Override any message or fix label.

Partial<typeof DIMENSION_MESSAGES>—

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

Accessibility

  • Each side and the unit have their own <label>
  • Fields are described by an aria-live="polite" status
  • Highlight animation respects prefers-reduced-motion

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

Limitations

  • Plausibility checks need a category; without one it only reads back
  • The default volumetric divisor may not match your courier

What it stops

Wrong package size ships

Also known as

dimensions · lxwxh · length width height · package size · shipping · volumetric weight · shiprocket · listing

Field type

Dependencies

Pairs well with