DitherCharts

Range slider

Updated

RangeSlider picks a low and a high value on one dithered track, for min-max filters. Each thumb is a native range input, so arrow keys, Page Up/Down and Home/End work, and the thumbs can't pass each other. Like the charts, it takes your theme's ink and paper, light or dark, and needs no Tailwind.

Example

Price
Locked
import "@/components/dithercharts/controls.css"
import { RangeSlider } from "@/components/dithercharts/range-slider"

<RangeSlider
  label="Price"
  min={0}
  max={500}
  step={10}
  defaultValue={[120, 360]}
  name="price" // submits price-min and price-max
  onValueChange={([low, high]) => setPrice({ low, high })}
/>

Install

Controls install with DitherCharts Pro. See Installation to log in, then import controls.css once, e.g. in your root layout.

npx dithercharts add range-slider

Props

It renders a native element, so every other attribute that element takes passes through.

RangeSlider props
PropTypeDefaultDescription
labelrequiredType ReactNodeDefault –The caption above the track, and both thumbs' accessible name with "minimum" or "maximum" after it.
hideLabelType booleanDefault falseKeeps the label for screen readers only; the values hide with it.
showValueType booleanDefault trueShows the current range beside the label.
minType numberDefault –
maxType numberDefault –
stepType numberDefault –
valueType readonly [number, number]Default –The chosen [low, high], for a controlled slider; pair it with onValueChange.
defaultValueType readonly [number, number]Default the whole rangeThe [low, high] at first, for an uncontrolled slider.
onValueChangeType (value: [number, number]) => voidDefault –Called with the new [low, high] as either thumb moves.
nameType stringDefault –The inputs' form field names are ${name}-min and ${name}-max.
disabledType booleanDefault –
classNameType stringDefault –