Measurement
A tape-measure value input with a sliding tick scale, fixed needle, flick momentum, tick snapping, rubber-band ends, and a rolling numeric readout.
import { MeasurementInput } from '@uthereal/ui/measurement-input'Measurement input playground
Overview
MeasurementInput renders a labelled measurement control shaped like a tape measure. A centered rolling readout sits above a full-width ruler viewport whose ticks slide under a fixed accent needle. Users drag the tape 1:1, flick it to coast with momentum onto a tick, tap any spot to glide that tick to the needle, scroll horizontally on a trackpad, or step with the keyboard.
The tape always rests on the step grid between min and max. Tick marks render with three stacked CSS gradients rather than per-tick DOM nodes, so wide scales stay fast.
| Capability | Behavior |
|---|---|
| Scale geometry | Defined by min (0), max (100), step (1), majorEvery (10 small ticks per label), and spacing (10px) |
| Direct gestures | 1:1 pointer drag, flick inertia with tick snapping, asymptotic rubber-band ends (44px), tap-to-glide, horizontal wheel pan |
| Readout & labels | Rolling odometer digits carry step precision (plus unit); major tick labels trim trailing zeros (30, 35, 40) |
| Formatting & form | Locale-aware Intl.NumberFormat via valueFormat and locale; emits a hidden <input type="hidden"> when name is set |
Use MeasurementInput for physical quantities adjusted by feel, such as height, weight, exposure, focal length, or temperature. Use Number when users type exact figures with steppers, or Range when approximate position or a two-thumb interval fits better.
Usage
'use client'
import { useState } from 'react'
import { MeasurementInput } from '@uthereal/ui/measurement-input'
export function HeightInput() {
const [height, setHeight] = useState(172)
return (
<MeasurementInput
label="Height"
name="height_cm"
min={120}
max={220}
step={1}
majorEvery={10}
unit="cm"
value={height}
onValueChange={setHeight}
onValueCommit={(next) => console.log('committed', next)}
/>
)
}Omit value for an uncontrolled ruler initialized from defaultValue (snapped to the step grid, or min when omitted). onValueChange fires on every tick passing under the needle during drags, coasts, and wheel scrolling; onValueCommit runs once the tape comes to rest after a drag, flick, tap, wheel settle, or key press. When name is set, a hidden <input type="hidden"> submits the current numeric value with native HTML forms.
Examples
Decimal precision and physical scales
Set a fractional step (such as 0.5) to give the rolling readout fixed decimal precision while major tick labels stay free of redundant trailing zeros. Increase spacing (up to 32px) to widen the distance between ticks for finer pointer control.
Formatted scales and dense rulers
Use valueFormat (decimal, percent, or currency) with locale to format both the rolling readout and major tick labels deterministically on server and client. Combine tighter spacing, higher majorEvery, and size="sm" for long ranges such as focal lengths or pixel dimensions.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Measurement" | Visible label and accessible name of the ruler, e.g. "Height" or "Focus distance". |
hideLabel | booleanDefault: false | Hide the label visually when the context already names the field. It is still announced. |
description | string— | Supporting text below the field, announced with it. Use it for format hints and constraints. |
error | string— | Validation message from your application. Setting it marks the field invalid; the message is linked to the field and announced politely. |
disabled | booleanDefault: false | Unavailable and removed from the tab order. A disabled field is not submitted with a form. |
name | string— | Native form field name, submitted with the value in a form. |
min | number— | Lowest value on the scale. Defaults to 0. |
max | number— | Highest value on the scale. Defaults to 100. |
defaultValue | number— | Initial value under the needle; omitted uses min. Edits do not reset a mounted instance. |
step | numberDefault: 1 | Value of one small tick; the tape always rests on a tick. Arrow keys move one step. |
largeStep | number— | Amount for PageUp, PageDown, and Shift+arrow. Omit for one labelled tick (step times majorEvery). |
majorEvery | integerDefault: 10 | Small ticks per labelled tick, 2 to 50; default 10. |
spacing | numberDefault: 10 | Pixels between small ticks, 4 to 32 (default 10). Wider spacing gives finer control. |
unit | string— | Short unit shown after the readout and spoken with the value, e.g. "cm" or "px". |
valueFormat | NumberFormat— | Intl display format: style decimal, percent (0.25 shows 25%), or currency, plus optional fraction digits. Omitted fraction digits follow the step precision. |
locale | string— | BCP 47 locale for separators and currency symbols, e.g. en-US or de-CH. Omit to inherit the application locale. |
size | sm | md | lgDefault: "md" | Tape height and text size: sm, md, or lg. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | MeasurementInputTheme— | Color mode, accent, and semantic tokens, plus the tape height. |
motion | none | subtle | expressiveDefault: "subtle" | Tape glide, flick momentum, and rolling digits. None and system reduced motion snap straight to the tick without coasting or rubber-banding. |
motionOptions | MeasurementInputMotionOptions— | transition: how the tape springs to a new value (Arc snappy spring by default). Durations are milliseconds. |
dir | ltr | rtl— | Reading direction. Omit to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
value, onValueChange | Controlled numeric value under the needle. onValueChange fires on every tick in both modes. |
onValueCommit(value) | Settled tick value after a drag, flick coast, tap glide, wheel settle, or key press. |
formatValue(value) | Custom formatter for the readout, major tick labels, and aria-valuetext; overrides valueFormat. |
ref | Ref to the root field <div> element. |
preset | Application defaults (such as locale, spacing, and theme), overridden by instance props. |
tokens | CSS custom properties (--ui-*) applied after the typed theme on the field root. |
className, style | Applied to the root field element, which carries the resolved --ui-* tokens. |
| Native attributes | Forwarded to the field root <div> (id wires the slider viewport, aria-describedby, data-*). |
Keyboard & accessibility
| Key | Interaction |
|---|---|
ArrowRight, ArrowUp | Increase by one step (ArrowRight decreases in dir="rtl"). |
ArrowLeft, ArrowDown | Decrease by one step (ArrowLeft increases in dir="rtl"). |
Shift + arrows, PageUp/PageDown | Move by largeStep (step × majorEvery when omitted). |
Home, End | Jump directly to min or max. |
The ruler viewport is a single focusable control with role="slider", aria-orientation="horizontal", aria-valuemin, aria-valuemax, aria-valuenow, and aria-valuetext combining the formatted number and unit. aria-labelledby links the field label (<span>), aria-describedby links description and error, and aria-invalid reflects error state. The rolling readout and center needle set aria-hidden="true" so assistive technology announces the value once.
In dir="rtl", the scale origin, tick gradient tiling, tick label offsets, drag direction, tap direction, horizontal wheel direction, and left/right arrow keys mirror from the inline start. Rolling digit columns and tick labels stay left-to-right so multi-digit and negative numbers never reverse. Under forced-colors: active, the viewport, invalid outline, Highlight needle, focus ring, tick lines, and readout text preserve system contrast.
Motion and theming
- Drag and rubber-band ends: dragging tracks the pointer 1:1. Pulling past
minormaxapplies asymptotic rubber-band resistance up to44pxand springs back on release (0.5s, bounce0.1). - Flick inertia: releasing a fast drag coasts with momentum (
power: 0.42,timeConstant: 260), updating the rolling readout as each tick crosses the needle and settling cleanly onto a tick. - Glides and rolling digits: key presses, taps, horizontal trackpad settles (
120ms), and external value changes glide onmotionOptions.transition(Arc snappy spring0.26s, bounce0.12by default) while preserving existing velocity. Digit columns share the resolved transition timing, and appearing or leaving place columns open or close width on the morph spring (0.42s, bounce0.16). - Reduced motion:
prefers-reduced-motion: reduceandmotion="none"disable flick inertia, rubber-band stretch, tape glides, and digit rolls, jumping directly to ticks (0ms).
theme accepts the core and control token groups, plus borderStrong and one component token: height (--ui-measurement-input-height, defaulting to 64px for sm, 72px for md, and 84px for lg). Tick colors resolve from --ui-text via --ui-measurement-input-tick and --ui-measurement-input-tick-major and can be overridden with tokens. An optional UtherealProvider supplies application-wide defaults.
Composition
MeasurementInput is a leaf component. Its numeric value is host state at /fields/instance-<id>/value, initialized from defaultValue snapped to the step grid (or min when omitted). Stored finite numbers remain intact across configuration edits while they stay within [min, max] and on the step grid. See Building with agents.
{
"type": "MeasurementInput",
"props": {
"label": "Focus distance",
"min": 0.5,
"max": 20,
"step": 0.5,
"majorEvery": 4,
"spacing": 14,
"unit": "m",
"defaultValue": 3.5
},
"children": []
}