RangeSlider
One track with two thumbs: from and to. For choosing a stretch inside a range, like «requests that took between 200 and 800 ms».
import { RangeSlider } from '@sypnia/ui/react'
Between two values
Requests filtered by how long they took.
Showing requests that took from 200 to 800 ms.
Code
import { useState } from 'react';
import { Field, RangeSlider } from '@sypnia/ui/react';
export default function Basic() {
const [range, setRange] = useState<[number, number]>([200, 800]);
return (
<Field label="Duration" hint={`Showing requests that took from ${range[0]} to ${range[1]} ms.`}>
<RangeSlider value={range} onChange={setRange} max={2000} step={50} formatOptions={{ style: 'unit', unit: 'millisecond' }} />
</Field>
);
} Disabled
The stretch stays in sight; the hint says why it cannot be moved.
Clear the search to filter by price.
Code
import { Field, RangeSlider } from '@sypnia/ui/react';
export default function States() {
return (
<Field label="Price" hint="Clear the search to filter by price.">
<RangeSlider disabled defaultValue={[20, 60]} formatOptions={{ style: 'currency', currency: 'USD', maximumFractionDigits: 0 }} />
</Field>
);
} When to use it
Use it when
- A filter between two numbers of the same scale: a duration, a price, an age, a size.
- Both ends are in sight and can be moved without typing.
Do not use it when
- Only one end moves: Slider.
- The ends are dates: DateRangePicker.
- Exact figures matter: two NumberInputs, «from» and «to».
For everyone
- Each thumb is a
sliderof its own, named «From» and «To» after the name of the control. Tab goes from one to the other. - Arrows move the focused thumb one step. A thumb never crosses the other one.
- Clicking the track moves the nearest thumb.
- The value is written beside the track as «from – to», with its unit.
Props
| RangeSlider | Type | Default |
|---|---|---|
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
defaultValue | [number, number] | |
disabled | boolean | |
formatOptionsHow the value is written beside the track, as in Intl.NumberFormat: `{ style: 'percent' }`, `{ style: 'unit', unit: 'gigabyte' }`. | NumberFormatOptions | |
idInside a Field it comes from the Field. | string | |
max | number | |
min | number | |
onChange | ((value: [number, number]) => void) | |
onChangeEnd | ((value: [number, number]) => void) | |
step | number | |
value[from, to] | [number, number] |