How it works
The reading is a registered custom property (@property, a number in steps). The track takes it from the chosen index, and one transition on it glides taps and keyboard changes and springs a released drag onto the nearest step. While dragging, the exact position goes straight into the track's inline style, so React only renders when the step changes. Each tick knows its own position and works out in CSS how close the reading is (k = max(0, 1 − |t − p| ÷ 3.2), smoothed to s = k²(3 − 2k)); it swells with scaleY by 1 + 1.35 × s and brightens, so the lens slides smoothly between steps instead of jumping. The ink pill sits at the end of a rail as wide as the tick row, moved with transform by p ÷ last × 100%, and the row of labels underneath marks every few steps.
Use it for
- Scrubbing through an ordered series where the value matters more than the exact control: hours of a forecast, frames, days of a plan, sizes.
- Touch screens, where dragging along a wide strip is easier than hitting a small thumb.
- When a large readout elsewhere on the card should follow the finger step by step.
Look elsewhere when
- Exact or free numeric input: use a number input or a range slider with a value field.
- Picking a range with two ends: use a range slider.
Usage
import { useState } from 'react'
import { ScrubRuler } from './ScrubRuler.jsx'
const steps = ['Now', '3 PM', '4 PM', '5 PM', '6 PM', '7 PM', '8 PM'].map((label, i) => ({
label,
value: [18, 18, 17, 16, 15, 14, 13][i],
}))
export function HourPicker() {
const [hour, setHour] = useState(0)
return (
<>
<p>{steps[hour].value}°</p>
<ScrubRuler
label="Forecast hour"
steps={steps}
value={hour}
onChange={setHour}
markEvery={3}
formatValue={(value, step) => `${step.label}, ${value}°`}
/>
</>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
steps | { label, value? }[] | — | The stops along the ruler, in order. label shows in the pill and under the marks; value is read out with it. |
value / defaultValue / onChange | number / number / (index, step) => void | - / 0 / - | The chosen step's index, controlled or uncontrolled. onChange fires each time a drag crosses into another step, so what depends on it can follow the finger. |
formatValue | (value, step, index) => string | — | Text read by screen readers for a step (aria-valuetext). By default the label, followed by the value when there is one. |
markEvery / renderMark | number / (step, index) => ReactNode | 0 / step.label | Every how many steps a taller tick gets a label under it; 0 shows no labels. PageUp and PageDown move by the same amount. renderMark replaces the label text. |
subdivisions | number | 2 | Ticks per step: 2 adds one short tick between neighbouring steps, 1 draws steps only. |
lens | boolean | true | Ticks within about three steps of the reading swell into a smooth bulge and brighten. Off, they stay flat. |
label | string | 'Value' | Accessible name of the slider. |
...rest | HTMLAttributes | — | Other attributes go to the root <div>. |
Accessibility
- The track is role="slider" with aria-valuemin, aria-valuemax, aria-valuenow and aria-valuetext from formatValue, named by label; the ticks, pill and labels are hidden from assistive tech.
- Left and Down go back a step, Right and Up go forward, PageUp and PageDown move by markEvery, Home and End go to the ends; focus shows a ring around the whole ruler.
- touch-action: pan-y keeps vertical page scrolling: a finger only changes the value when it moves sideways or lifts without moving, so a scroll that starts on the ruler leaves it alone. The whole ruler, not just the pill, is the hit area.
- The current tick turns ink and is the tallest, so the reading does not rely on colour alone.
- Reduced motion moves the reading straight to each step; a drag still follows the pointer.
Motion
Reading: the registered property transitions over 420ms cubic-bezier(0.34, 1.3, 0.5, 1), a short overshoot onto the step; while dragging it follows within 90ms. Ticks: scaleY and opacity follow the reading every frame. Pill text: rises 3px and fades in over 160ms on each new step.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
ScrubRuler.jsxscrub-ruler.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.







