Range
A unified range control supporting standard, elastic, histogram, window, and lens layouts.
import { RangeInput } from '@uthereal/ui/range-input'Range input playground
Overview
RangeInput unifies five range selection archetypes behind one schema, shared numeric math, and consistent field anatomy. Use layout to pick the interaction model that fits your scale. All five layouts share min, max, step, largeStep, marks, valueFormat, unit, and onValueChange / onValueCommit.
| Layout | Thumbs | Required data | Role of marks | Best for |
|---|---|---|---|---|
standard | 1 or 2 | None | Track ticks and labels | General single values, two-thumb ranges, and vertical scales. |
elastic | 1 | None | Tactile magnetic detents | Tactile settings with rubber-band ends and swaying value tag. |
histogram | 2 | Sample array | Unused | Filtering numeric distributions such as prices or durations. |
window | 2 + pan | Time series | Axis tick labels | Selecting and panning a time window over an area chart. |
lens | 2 | None | Magnetic dock presets | Fine scales with benchmark stops and fusing value bubbles. |
Use RangeInput when approximate position or data shape guides the choice. When the user must type an exact number, use Number. For a single value on a scrolling tape measure, use Measurement.
Usage
'use client'
import { useState } from 'react'
import { RangeInput } from '@uthereal/ui/range-input'
export function PriceFilter() {
const [range, setRange] = useState([20, 80])
return (
<RangeInput
label="Price"
thumbLabels={['Minimum price', 'Maximum price']}
valueFormat={{
style: 'currency',
currency: 'USD',
maximumFractionDigits: 0,
}}
value={range}
onValueChange={setRange}
onValueCommit={(next) => console.log('commit', next)}
/>
)
}onValueChange emits a canonical number[] on every movement. onValueCommit runs once a drag, flick coast, or keyboard action settles.
Examples
Elastic
Set layout="elastic" for a single-thumb track that stretches past either limit and pushes startIcon and endIcon outward. marks act as tactile magnetic detents with tick feedback, and a trailing value tag tilts with thumb speed.
Histogram
Set layout="histogram" with raw sample numbers in data. Bars inside the selected range light up on the exact same frame as the track fill, and released thumbs settle onto bar edges when snapToBins is enabled.
Window
Set layout="window" with an evenly-spaced time series in data. Drag either handle to resize, drag or flick inside the frame to pan with momentum, and enable live to pulse a dot on the latest point.
Lens
Set layout="lens" for a fine scale that magnifies ticks under each thumb like a dock. marks act as magnetic presets reachable by pointer or keyboard, and value bubbles fuse into one pill when the thumbs meet.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Range" | Visible label and accessible name of the group or thumbs, e.g. "Price" or "Report dates". |
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. |
readOnly | booleanDefault: false | The value can be focused, selected, and copied, but not edited. It is still submitted with a form. |
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. |
layout | 'standard' | 'elastic' | 'histogram' | 'window' | 'lens'Default: "standard" | Interaction archetype: standard (single or dual slider), elastic (single-thumb rubber-band track with swaying tag), histogram (dual range over a bar distribution), window (resizable, flick-to-pan window over an area chart), or lens (fisheye magnifying ticks with fusing value bubbles). |
min | number— | Lowest value on the scale. Defaults to 0, or the smallest value in data for histogram. |
max | number— | Highest value on the scale. Defaults to 100, the largest data value in histogram, or data.length - 1 in window. |
step | numberDefault: 1 | Smallest increment. Arrow keys move one step. |
largeStep | number— | Increment for Page Up, Page Down, and Shift+arrow. Omit for a tenth of the span, or the next bar edge in histogram. |
defaultValue | number | [number, number]— | Initial value: a single number (or [v]) for one thumb, or [min, max] for a range. Omit to use the layout default. |
minStepsBetweenThumbs | integerDefault: 0 | Closest two thumbs may sit, in steps. Also defines the minimum window width in window layout. |
maxSpan | number— | Widest allowed range (end minus start) in domain units. Omit to allow the full span. |
marks | RangeMark[]— | Scale stops: track marks in standard, tactile snap detents in elastic, axis ticks in window, and magnetic dock presets in lens. |
data | number[]— | Numeric array required by histogram (raw samples bucketed into bins) and window (evenly-spaced time series). |
bins | integerDefault: 32 | Number of histogram bars (4 to 60, default 32). Used in histogram layout. |
snapToBins | booleanDefault: true | In histogram layout, released thumbs near a bar edge settle onto that bar boundary. |
chartHeight | integer— | Chart height in px (48 to 240). Defaults to 76 in histogram and 112 in window. |
live | booleanDefault: false | In window layout, pulses a live dot on the latest data point. |
magnet | numberDefault: 16 | In lens layout, pixel reach of magnetic preset detents (0 disables detents, default 16). |
showValue | booleanDefault: true | Show the formatted readout (header readout, window start/span/end row, or fusing lens bubbles). |
valueFormat | NumberFormat— | Intl display format: style decimal, percent (0.25 shows 25%), or currency, plus fraction digits. |
unit | string— | Short unit suffix appended after formatted numbers, e.g. "dB", "px", or "days". |
thumbLabels | [string, string]— | Accessible names of a two-thumb range, e.g. ["Minimum price", "Maximum price"]. Defaults to "{label}, minimum" and "{label}, maximum". |
startIcon | plus | minus | x | check | pencil | trash-2 | copy | download | upload | share-2 | external-link | link | refresh-cw | rotate-ccw | search | filter | settings | ellipsis | ellipsis-vertical | eye | eye-off | lock | log-out | send | square | paperclip | mic | star | chevron-down | chevron-up | chevron-left | chevron-right | chevrons-up-down | arrow-left | arrow-right | arrow-up | arrow-down | menu | panel-left | maximize-2 | minimize-2 | file | file-text | folder | image | table | book-open | globe | calendar | code | message-square | sparkles | bot | user | brain | wrench | terminal | thumbs-up | thumbs-down | list-checks | info | circle-check | triangle-alert | circle-x | circle-help | clock | circle | circle-dashed | bell | loader-circle | mail | phone | chevrons-down-up | pipette | hash | bookmark | headphones | video | presentation | archive | circle-alert | sun | moon | monitor | command | folder-open | play | pause | file-image | file-play | file-archive | message-circle | check-check | circle-dot | smile-plus | corner-down-right | rotate-cw | file-code-corner | copy-plus | pin | git-pull-request | git-merge | git-pull-request-closed | file-diff | sun-moon | user-round | credit-card | calendar-days | signal-high | camera | image-plus | heart | bell-off— | Curated icon before the track in standard and elastic layouts. Pushes outward during overpull in elastic. |
endIcon | plus | minus | x | check | pencil | trash-2 | copy | download | upload | share-2 | external-link | link | refresh-cw | rotate-ccw | search | filter | settings | ellipsis | ellipsis-vertical | eye | eye-off | lock | log-out | send | square | paperclip | mic | star | chevron-down | chevron-up | chevron-left | chevron-right | chevrons-up-down | arrow-left | arrow-right | arrow-up | arrow-down | menu | panel-left | maximize-2 | minimize-2 | file | file-text | folder | image | table | book-open | globe | calendar | code | message-square | sparkles | bot | user | brain | wrench | terminal | thumbs-up | thumbs-down | list-checks | info | circle-check | triangle-alert | circle-x | circle-help | clock | circle | circle-dashed | bell | loader-circle | mail | phone | chevrons-down-up | pipette | hash | bookmark | headphones | video | presentation | archive | circle-alert | sun | moon | monitor | command | folder-open | play | pause | file-image | file-play | file-archive | message-circle | check-check | circle-dot | smile-plus | corner-down-right | rotate-cw | file-code-corner | copy-plus | pin | git-pull-request | git-merge | git-pull-request-closed | file-diff | sun-moon | user-round | credit-card | calendar-days | signal-high | camera | image-plus | heart | bell-off— | Curated icon after the track in standard and elastic layouts. Pushes outward during overpull in elastic. |
orientation | horizontal | verticalDefault: "horizontal" | Horizontal (default) or vertical. Vertical orientation is supported in standard layout. |
size | sm | md | lgDefault: "md" | Thumb, track, and text size: sm, md, or lg. |
recipe | studio | softDefault: "studio" | Visual treatment. Both studio and soft share identical interaction behavior. |
theme | RangeInputTheme— | Color mode, accent, and semantic tokens, plus thumbSize, trackThickness, length, and chartHeight. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. None and system reduced motion jump directly without coasting, rubber-banding, or pulse. |
motionOptions | RangeInputMotionOptions— | transition: how thumbs and fills spring to a new value (Arc snappy spring by default). Durations are milliseconds. |
dir | ltr | rtl— | Reading direction. Omit to inherit the page direction. |
locale | string— | BCP 47 locale for separators and currency symbols, e.g. en-US or de-CH. Omit to inherit the application locale. |
React integration
| Prop | Purpose |
|---|---|
value, onValueChange | Controlled value (number or readonly number[]) and canonical number[] hook. |
onValueCommit(value) | Fires once a drag, flick coast, preset click, or key action settles. |
formatValue(value) | Custom value formatter; overrides valueFormat and unit. |
formatSpan(span) | null | Formats the middle span readout in window layout; pass null to hide it. |
start, end | Custom leading or trailing slots for standard and elastic (override icons). |
ref | The field root element. |
preset | Application defaults, overridden by explicit instance props. |
tokens | CSS variables applied after the typed theme. |
className, style | Added to the field root element. |
| Native attributes | id (first slider control id), aria-describedby, data-*. |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab | Moves through each role="slider" thumb (plus window body in window, presets in lens). |
| Arrow keys | Move one step (direction follows dir on standard, elastic, histogram, and lens; window stays chronological left-to-right). |
Shift + arrow, PageUp, PageDown | Move largeStep (or the next bar edge in histogram). |
Home, End | Jump to the slider's minimum or maximum allowed bound. |
Enter, Space (on lens preset) | Move the nearest thumb onto that preset. |
Every thumb and window handle exposes role="slider" with aria-valuemin, aria-valuemax, aria-valuenow, and formatted aria-valuetext. Thumbs never cross and respect minStepsBetweenThumbs and maxSpan. Pointer focus stays quiet until keyboard navigation begins. All layouts support forced-colors: active and submit hidden form inputs when name is set.
Motion and theming
All pointer drags, overpull stretches, fisheye tick displacements, and area clips update through motion values or 240 Hz requestAnimationFrame loops that pause when idle, offscreen, or in background tabs.
standardandelasticrubber-band past limits and spring onto the step grid or magnetic detents.histogramsyncs bar illumination and track fill through one shared clip path and shows a hairline guide while dragging.windowprojects pan flicks into a critically damped coast and morphs area paths whendataupdates.lensspreads and swells nearby ticks with a Gaussian fisheye and springs bubble widths and fusion bridges.motion="none"andprefers-reduced-motion: reducedisable rubber-banding, coasting, trailing, chart morphs, and the live dot pulse while keeping full pointer, keyboard, and detent behavior.
theme accepts the core, control, and selectionControl token groups, plus shadowRaised, borderStrong, series1, and component tokens thumbSize, trackThickness, length, and chartHeight.
Composition
RangeInput is a leaf component. Its canonical number[] value is host state at /fields/instance-<id>/value. Stored values remain intact while they fit the layout's thumb count, domain bounds, and span limits.
{
"type": "RangeInput",
"props": {
"label": "Salary band",
"layout": "lens",
"min": 40000,
"max": 160000,
"step": 1000,
"defaultValue": [74000, 96000],
"marks": [
{ "value": 62000, "label": "Entry" },
{ "value": 82000, "label": "Median" },
{ "value": 104000, "label": "Top quarter" }
],
"valueFormat": {
"style": "currency",
"currency": "USD",
"maximumFractionDigits": 0
}
},
"children": []
}