UI

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

Height
120130140150160170180190200210220
Loading interactive preview…

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.

CapabilityBehavior
Scale geometryDefined by min (0), max (100), step (1), majorEvery (10 small ticks per label), and spacing (10px)
Direct gestures1:1 pointer drag, flick inertia with tick snapping, asymptotic rubber-band ends (44px), tap-to-glide, horizontal wheel pan
Readout & labelsRolling odometer digits carry step precision (plus unit); major tick labels trim trailing zeros (30, 35, 40)
Formatting & formLocale-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.

Body weight
404550556065707580859095100105110115120125130135140

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.

Opacity
0%20%40%60%80%100%
Focal length
1464114164214264314364

API reference

These serializable arguments and defaults come directly from the component schema.

ArgumentType / defaultDescription
labelstringDefault: "Measurement"Visible label and accessible name of the ruler, e.g. "Height" or "Focus distance".
hideLabelbooleanDefault: falseHide the label visually when the context already names the field. It is still announced.
descriptionstring—Supporting text below the field, announced with it. Use it for format hints and constraints.
errorstring—Validation message from your application. Setting it marks the field invalid; the message is linked to the field and announced politely.
disabledbooleanDefault: falseUnavailable and removed from the tab order. A disabled field is not submitted with a form.
namestring—Native form field name, submitted with the value in a form.
minnumber—Lowest value on the scale. Defaults to 0.
maxnumber—Highest value on the scale. Defaults to 100.
defaultValuenumber—Initial value under the needle; omitted uses min. Edits do not reset a mounted instance.
stepnumberDefault: 1Value of one small tick; the tape always rests on a tick. Arrow keys move one step.
largeStepnumber—Amount for PageUp, PageDown, and Shift+arrow. Omit for one labelled tick (step times majorEvery).
majorEveryintegerDefault: 10Small ticks per labelled tick, 2 to 50; default 10.
spacingnumberDefault: 10Pixels between small ticks, 4 to 32 (default 10). Wider spacing gives finer control.
unitstring—Short unit shown after the readout and spoken with the value, e.g. "cm" or "px".
valueFormatNumberFormat—Intl display format: style decimal, percent (0.25 shows 25%), or currency, plus optional fraction digits. Omitted fraction digits follow the step precision.
localestring—BCP 47 locale for separators and currency symbols, e.g. en-US or de-CH. Omit to inherit the application locale.
sizesm | md | lgDefault: "md"Tape height and text size: sm, md, or lg.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeMeasurementInputTheme—Color mode, accent, and semantic tokens, plus the tape height.
motionnone | 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.
motionOptionsMeasurementInputMotionOptions—transition: how the tape springs to a new value (Arc snappy spring by default). Durations are milliseconds.
dirltr | rtl—Reading direction. Omit to inherit the page direction.

React integration

PropPurpose
value, onValueChangeControlled 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.
refRef to the root field <div> element.
presetApplication defaults (such as locale, spacing, and theme), overridden by instance props.
tokensCSS custom properties (--ui-*) applied after the typed theme on the field root.
className, styleApplied to the root field element, which carries the resolved --ui-* tokens.
Native attributesForwarded to the field root <div> (id wires the slider viewport, aria-describedby, data-*).

Keyboard & accessibility

KeyInteraction
ArrowRight, ArrowUpIncrease by one step (ArrowRight decreases in dir="rtl").
ArrowLeft, ArrowDownDecrease by one step (ArrowLeft increases in dir="rtl").
Shift + arrows, PageUp/PageDownMove by largeStep (step × majorEvery when omitted).
Home, EndJump 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 min or max applies asymptotic rubber-band resistance up to 44px and springs back on release (0.5s, bounce 0.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 on motionOptions.transition (Arc snappy spring 0.26s, bounce 0.12 by 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, bounce 0.16).
  • Reduced motion: prefers-reduced-motion: reduce and motion="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": []
}

On this page