Skip to content
Haze UI

Ruler slider

An adjustable measurement with a draggable tick tape, fixed needle and native slider fallback.

pnpm dlx shadcn@latest add @haze/ruler-slider
Open preview in a new tab
Livesmall script

When to use

  • Choosing a physical measurement benefits from a visible ruler and explicit unit.
  • Touch users should be able to drag the scale while keyboard users keep a familiar range input.

When not to use

  • Use input for an exact measurement that people will usually type.
  • Use elastic-slider when named presets matter more than a continuous scale.

Installation

Add the Haze registry to components.json once, then install Ruler slider with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/ruler-slider
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Unique caller supplied prefix for the control and its associated content.
namestringidName submitted by the native form control.
labelstringDesk heightVisible measurement name.
minnumber60Beginning of the tape.
maxnumber130End of the tape.
stepnumber1Smallest selectable increment.
valuenumber74Initial measurement.
unitstringcmUnit shown and spoken with the measurement.
disabledbooleanfalsePrevents user changes through the native disabled state.
classstring–Additional classes on this component's outer wrapper.
[key: string]unknown–Other range attributes forwarded to the native Slider.

Keyboard interactions

Arrow keys
Increase or decrease by the supplied measurement step.
HomeEnd
Reach the shortest or longest measurement.

Accessibility

  • The tape and needle are decorative; the labelled native range stays visible for keyboard users and when scripts are unavailable.
  • Horizontal dragging waits for an axis decision, allowing a vertical touch gesture to scroll the page.
  • A canceled pointer gesture restores the measurement from before the drag.
  • The accessible value includes the chosen unit, while the tick count is capped so large domains do not create unbounded markup.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Ruler slider" with `npx shadcn@latest add @haze/ruler-slider`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import RulerSlider from "@/components/haze/ui/ruler-slider.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/ruler-slider.md

  • Customize with real content

    Adapt the Haze ruler-slider ui for our product. Replace the demo values of these props with our real content: id, name, label, min, max, step, value, unit, disabled, class, [key: string]. Keep the layout, the heading level rules and these accessibility details: The tape and needle are decorative; the labelled native range stays visible for keyboard users and when scripts are unavailable. Horizontal dragging waits for an axis decision, allowing a vertical touch gesture to scroll the page. A canceled pointer gesture restores the measurement from before the drag. The accessible value includes the chosen unit, while the tick count is capped so large domains do not create unbounded markup. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using ruler-slider, check it fits: use it when choosing a physical measurement benefits from a visible ruler and explicit unit.; touch users should be able to drag the scale while keyboard users keep a familiar range input.. Avoid it when use input for an exact measurement that people will usually type.; use elastic-slider when named presets matter more than a continuous scale.. Alternatives: @haze/slider, @haze/input, @haze/elastic-slider.

Dependencies

  • @haze/slider
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog