UI

Scrub

A compact inspector number field with drag-to-scrub handles, mouse pointer lock, inline arithmetic, unit cycling, rubber-band limits, and double-click reset.

import { ScrubInput } from '@uthereal/ui/scrub-input'

Scrub input playground

Loading interactive preview…

Overview

ScrubInput renders a compact numeric row designed for inspectors and property panels. Users drag the label handle horizontally to scrub the value, click in to type numbers or arithmetic expressions, step with arrow keys, or double-click the handle to restore resetValue.

When both min and max are set, a quiet background fill tracks the value across its range by default. At either limit, dragging strains the shell with rubber-band resistance and springs back on release unless wrap is enabled.

CapabilityBehavior
Handle scrubbingHorizontal drag after 3px slop; mouse drags request pointer lock with a wrapping virtual cursor when pointerLock is on
Step modifiersShift steps by coarseStep (10 × step, snapped to the coarse grid); Alt steps by fineStep (0.1 × step)
Inline arithmeticEvaluates +, -, *, /, parentheses, unary signs, decimal commas, ×/÷/−, and known units (with deg/°)
Limits & wrapClamps between min and max with rubber-band strain, or wraps continuously when wrap is enabled with both limits
Units & resetCycles units from a trailing button when more than one unit is configured; double-clicking the handle sets resetValue
Form submissionEmits a hidden <input type="hidden"> carrying the current numeric value when name is set and the field is enabled

Use ScrubInput for compact layout, transform, and visual inspector parameters adjusted by feel or quick math. Use Number for standalone form inputs with steppers and locale formatting, Measurement for tape-measure physical scales, or Range for sliders and two-thumb intervals.

Usage

'use client'
import { useState } from 'react'
import { ScrubInput } from '@uthereal/ui/scrub-input'

export function WidthInspector() {
  const [width, setWidth] = useState(320)
  const [unit, setUnit] = useState('px')

  return (
    <ScrubInput
      label="W"
      name="width"
      min={0}
      max={1200}
      units={['px', 'rem', '%']}
      resetValue={320}
      value={width}
      unit={unit}
      onValueChange={(next) => setWidth(next)}
      onValueCommit={(next, details) =>
        console.log('committed', next, details.source, details.unit)
      }
      onUnitChange={setUnit}
    />
  )
}

Omit value or unit for an uncontrolled field initialized from defaultValue and defaultUnit (or the first entry of units). onValueChange fires on every step during a scrub, key press, typed commit, or reset; onValueCommit runs once a scrub ends, typing commits, a key step lands, or a double-click resets.

Examples

Bounded tracks, cyclic wrap, and unit cycling

Combine min and max for a proportional track fill and rubber-band ends, add wrap for cyclic quantities such as 0–360° rotation, or supply multiple units (["px", "rem", "%"]) so users can click the trailing unit badge or type a new unit inline (for example, 50% or (100-24)/2).

Precision scaling, icon handles, and compact rows

Use size="sm" for 30px rows, set icon to replace the visible label text with a 14px icon while keeping label as the accessible name, tune pixelsPerStep alongside fineStep and coarseStep for sensitive scales, and set track={false} when a centered signed scale reads clearer without a fill bar.

Expression syntax

Typed values pass through evaluateScrubExpression(text, units) on Enter or blur. Invalid syntax, division by zero, and unknown units reject the edit, restore the prior value, mark the field invalid for 900ms, and kick the shell gently.

InputResult
12*2, 12×2Evaluates multiplication (24)
(100-24)/2Evaluates grouped arithmetic (38)
1,5Parses comma decimal separator (1.5)
50%, (10+20)pxApplies the number and switches unit when listed in units
90deg, 90°Treats deg and ° as aliases when either is in units

API reference

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

ArgumentType / defaultDescription
labelstringDefault: "W"Short label on the grab handle, e.g. "W" or "Opacity". It stays the accessible name when an icon replaces it visually.
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.
iconIconName—Optional 14px icon shown as the handle instead of the label text. Any name from the Icons page.
defaultValuenumberDefault: 0Initial value. Later argument edits do not reset a mounted instance; use value and onValueChange to control it.
minnumber—Lowest allowed value. Omit for no lower limit.
maxnumber—Highest allowed value. Omit for no upper limit.
stepnumberDefault: 1Amount the arrows and one scrub step move. Shift multiplies it by ten, Alt takes a tenth.
fineStepnumber—Step with Alt held, snapped to its own grid. Omit for a tenth of step.
coarseStepnumber—Step with Shift held, snapped to its own grid. Omit for ten times step.
precisioninteger—Decimal places kept, 0 to 8. Omit to follow the steps (the fine step decides).
pixelsPerStepnumberDefault: 2Pointer travel in pixels for one step while scrubbing, 1 to 64. Default 2.
wrapbooleanDefault: falseWrap from max to min instead of stopping, as rotation does. Needs both limits.
defaultUnitstring—Initial unit shown after the number, e.g. "px". Edits do not reset a mounted instance.
unitsstring[]—Units a typed value may carry, e.g. ["px", "%"]. With more than one, the unit becomes a button that cycles them; "deg" and "°" are aliases.
resetValuenumber—Value a double click on the handle restores. Omit to disable the reset.
trackboolean—Fill showing how far the value sits between min and max. On by default when both limits are set.
pointerLockbooleanDefault: trueLock the mouse pointer while scrubbing so a long drag never runs out of screen. On by default; touch always uses pointer capture.
sizesm | mdDefault: "md"Row height and text size: 30px sm or 36px md.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeScrubInputTheme—Color mode, accent, and semantic tokens, plus row width and height.
motionnone | subtle | expressiveDefault: "subtle"Track glide, limit strain, shake, and unit swaps. System reduced motion removes travel, strain, and blur while keeping 120ms opacity fades; none makes every update immediate.
motionOptionsScrubInputMotionOptions—transition: the spring the track fill glides on (Arc smooth by default). Durations are milliseconds.
dirltr | rtl—Reading direction. Omit to inherit the page direction.

React integration

PropPurpose
value, onValueChangeControlled number and live change callback (value, { source, unit }) in both modes.
onValueCommitSettled value callback (value, { source, unit }) on scrub end, typed commit, key step, or reset.
unit, onUnitChangeControlled unit string and callback fired on unit button cycle or typed unit change.
labelShort text or a React node on the grab handle; supply aria-label if a React node has no text.
renderLabel()Custom handle renderer; keeps the string label visually hidden as the accessible name.
refRef to the native <input> element.
presetApplication defaults (such as size, pixelsPerStep, and theme), overridden by instance props.
tokensCSS custom properties (--ui-*) applied after the typed theme on the field root and cursor portal.
className, styleApplied to the root field element, which carries the resolved --ui-* tokens.
Native attributesForwarded to <input> (aria-label, aria-describedby, onFocus, onBlur, onKeyDown, id).

The pure expression parser evaluateScrubExpression is also exported from @uthereal/ui/scrub-input.

Keyboard & accessibility

Key / gestureInteraction
ArrowUp, ArrowDownCommits any open draft, then steps by step and selects the updated number.
Shift + arrows / scrubSteps or scrubs by coarseStep (10 × step), snapping keyboard steps to the coarse grid.
Alt + arrows / scrubSteps or scrubs by fineStep (0.1 × step).
EnterEvaluates and commits the typed expression, then re-selects the number.
EscapeCancels an active scrub back to its starting value, or discards an uncommitted typed draft.
Click / double-click handleClick focuses and selects the input; double-click restores resetValue when configured.

The text input exposes role="spinbutton" with aria-valuenow, finite aria-valuemin and aria-valuemax (omitted when unbounded), and aria-valuetext spelling out % as percent and deg/° as degrees. The grab handle is the field's single <label> element (htmlFor and aria-labelledby); when icon or renderLabel replaces its visible text, the string label remains visually hidden inside it. description and error wire into aria-describedby, and errors announce through role="alert".

In dir="rtl", the track fill origin, scrub drag delta, and rubber-band strain direction mirror from the inline start. The <input> stays dir="ltr" so negative numbers and arithmetic expressions never reverse visually while aligning next to the RTL handle. Under forced-colors: active, the shell, focus outline, invalid outline, Highlight track indicator, CanvasText handle and unit, and GrayText disabled state preserve system contrast.

Motion and theming

  • Track fill: follows handle drags 1:1 and glides to typed, stepped, reset, or external values on motionOptions.transition (Arc smooth spring by default, zero overshoot).
  • Limit strain and shake: dragging past min or max stretches the shell up to 12px with rubber-band resistance while leaning the value half as far, then springs back on release. Stepping past a limit or submitting invalid syntax triggers a short smooth-spring kick.
  • Unit swaps and modifiers: cycling units crossfades through a 2px vertical blur on the snappy spring; Shift/Alt multiplier badges spring in while scrubbing.
  • Reduced motion: prefers-reduced-motion: reduce disables fill glides, limit strain, shake, unit blur, travel, and press scale while keeping 120ms opacity crossfades. motion="none" makes every update immediate (0ms).

theme accepts the core and control token groups, plus borderStrong (focus and scrubbing edge), surfaceSunken (resting shell fill), and two component tokens: width (--ui-scrub-input-width, default 110px, capped at 100%) and height (--ui-scrub-input-height, 30px at sm and 36px at md). An optional UtherealProvider supplies application-wide defaults.

Composition

ScrubInput is a leaf component. Its numeric value and active unit are host state at /fields/instance-<id>/value and /fields/instance-<id>/unit, initialized from defaultValue and defaultUnit (or units[0]). Stored values survive configuration edits while they remain finite and within [min, max], and stored units survive while they remain listed in units. See Building with agents.

{
  "type": "ScrubInput",
  "props": {
    "label": "W",
    "min": 0,
    "max": 1200,
    "defaultValue": 320,
    "defaultUnit": "px",
    "units": ["px", "rem", "%"],
    "resetValue": 320
  },
  "children": []
}

On this page