Xzero UI
Pro library

Ruler slider

A tape of ticks that slides under a fixed needle, with momentum, snapping, and a rolling readout.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/ruler-slider
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/ruler-slider

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { RulerSlider } from "@/components/xzero/ruler-slider/ruler-slider";

export function HeightField() {
  const [height, setHeight] = useState(172);
  return (
    <RulerSlider
      label="Height"
      unit="cm"
      min={120}
      max={220}
      value={height}
      onValueChange={setHeight}
      onValueCommit={saveHeight}
    />
  );
}

API reference

RulerSlider

A precise value input shaped like a tape measure. A ruler of ticks slides under a fixed needle; drag it, flick it to coast onto a tick, tap to glide there, or scroll horizontally. The readout rolls each digit.

PropTypeDefaultDescription
label (required)string–Visible label. It also names the control.
valuenumber–Controlled value. Leave it out for uncontrolled use.
defaultValuenumberminInitial value when uncontrolled.
onValueChange(value: number) => void–Called whenever a tick passes the needle, including while coasting.
onValueCommit(value: number) => void–Called once the tape comes to rest after a drag, flick, tap, scroll, or key.
minnumber0Lowest value.
maxnumber100Highest value.
stepnumber1Value of one small tick. The tape always rests on a tick.
largeStepnumber–Distance for PageUp, PageDown, and Shift with an arrow. Defaults to one labelled tick (step × majorEvery).
majorEverynumber10Small ticks between labelled ticks.
spacingnumber10Pixels between small ticks. Wider spacing gives finer control.
format(value: number) => string–Formats the readout, the tick labels, and aria-valuetext.
unitstring–Unit shown after the readout and spoken with the value, such as "cm".
namestring–Submits the value with a form through a hidden input.
disabledbooleanfalseBlocks input and removes the control from the tab order.
classNamestring–Extra class on the root.

Keyboard interactions

KeysAction
ArrowRight / ArrowUpMoves one tick up.
ArrowLeft / ArrowDownMoves one tick down.
Shift + Arrow / PageUp / PageDownMoves one labelled tick (largeStep).
Home / EndGoes to min or max.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in sliders

Guidance for AI tools

Ruler slider: A tape of ticks that slides under a fixed needle, with momentum, snapping, and a rolling readout. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components