RangeSlider
A slider with two thumbs for picking a range. Use it for a pair of values, such as a minimum and a maximum price.
Import
Copy code
import { RangeSlider } from '@k8ordo/ui';Usage
Priceminimummaximum
Copy code
<RangeSlider aria-label="Price" defaultValue={[20, 80]} />Controlled
Temperatureminimummaximum
18–26 °C
Copy code
const [value, setValue] = useState<readonly [number, number]>([18, 26]);
<RangeSlider
aria-label="Temperature"
max={40}
min={0}
onChange={setValue}
value={value}
/>Disabled
Priceminimummaximum
Copy code
<RangeSlider aria-label="Price" defaultValue={[20, 80]} disabled />In a form
Each thumb is a real <input type="range">. They submit as two values, under the two names passed to name. Uncontrolled, a form’s reset and isDirty work on them as on any other input.
Copy code
// schema.ts
export const filterSchema = z.object({
priceMin: z.coerce.number().int().min(0).max(100),
priceMax: z.coerce.number().int().min(0).max(100),
});
// filter-form.tsx
const priceMin = form.field('priceMin');
const priceMax = form.field('priceMax');
<FormControl
label="Price"
renderInput={(props) => (
<RangeSlider
{...props}
defaultValue={[20, 80]}
max={100}
min={0}
name={[priceMin.input.name, priceMax.input.name]}
/>
)}
/>Props
defaultValue?- Type:
readonly [number, number] - Default: -
disabled?- Type:
boolean - Default:
false invalid?- Type:
boolean - Default:
false max?- Type:
number - Default:
100 min?- Type:
number - Default:
0 name?- Type:
readonly [string, string] - Default: -
onChange?- Type:
(value: [number, number]) => void - Default: -
ref?- Type:
Ref<HTMLDivElement> - Default: -
required?- Type:
boolean - Default:
false step?- Type:
number - Default:
1 value?- Type:
readonly [number, number] - Default: -
| Prop | Type | Default |
|---|---|---|
defaultValue? | readonly [number, number] | - |
disabled? | boolean | false |
invalid? | boolean | false |
max? | number | 100 |
min? | number | 0 |
name? | readonly [string, string] | - |
onChange? | (value: [number, number]) => void | - |
ref? | Ref<HTMLDivElement> | - |
required? | boolean | false |
step? | number | 1 |
value? | readonly [number, number] | - |
Inherited attributes (except the ones set internally): HTMLAttributes<HTMLDivElement>
The wording this component draws (labels, placeholders, and so on) comes from the message dictionary unless a prop sets it. To replace it, see: i18n