Components / Slider
Slider
A square, monospaced Radix slider for a value or range. Give every thumb a name, show the current value, and adjust with touch, pointer or keyboard.
Storybook is a separate local or hosted build; no hosted Storybook is configured. Source links match the install revision.
Usage playground
Adjust a volume or a two-thumb range with a pointer or keyboard. Visible feedback follows the controlled value; every thumb has its own accessible name.
Choose a level in steps of 5%.
'use client';
import { useId, useState } from 'react';
import { Slider } from '@/components/ui/yads-slider';
export default function VolumeExample() {
Installation
pnpm dlx [email protected] add biehlio/yet-another-design-system/slider#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40Documentation samples use basic Tailwind utilities for layout. Install each YADS component imported by the sample.
Run this revision-pinned command in a shadcn-configured project. It installs yads-slider, scoped CSS, @radix-ui/react-slider and pinned JetBrains Mono. Import { Slider } from @/components/ui/yads-slider. The primitive needs no site stylesheet, reset, Tailwind, theme provider or other YADS component. A containing .dark class selects dark colors; light is the default.
Copy sample returns a complete React module, including a client boundary and recipe CSS, even when collapsed. Sample layout uses basic Tailwind utilities. The form sample also imports Button: install it separately with pnpm dlx [email protected] add biehlio/yet-another-design-system/button#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40. Visible slider titles use spans with aria-labelledby, not native label htmlFor: Radix thumbs are not labelable inputs.
Range, help and errors
Use distinct thumbLabels; labeling the Root alone does not name each Radix thumb. Shared descriptions reach both thumbs. This example shows application-owned save feedback, not automatic validation. Arrow keys respect a $20 minimum gap; preserveThumbOrder keeps each thumb on its side.
Choose prices at least $20 apart, in $10 steps.
Could not save this range. Adjust it before retrying.
'use client';
import { useId, useState } from 'react';
import { Slider } from '@/components/ui/yads-slider';
export default function PriceRangeExample() {
Native form submission
Radix renders hidden inputs for named sliders: a single value uses name, a range uses repeated name[] entries. Uncontrolled form reset restores the initial values. This local demo sends no request.
Disabled is not native input exclusion. With the tested Radix 1.6.1, named disabled sliders still serialize. Filter application FormData or conditionally omit the slider if its value must not be sent. Required, readOnly and native text-input validity are not supported.
'use client';
import { useId, useState } from 'react';
import { Slider } from '@/components/ui/yads-slider';
import { Button } from '@/components/ui/yads-button';
className customization
Override the scoped fill variable with a sufficiently specific class, keeping thumb contrast and the keyboard outline. Root className and inline style pass through. The complete sample includes both-theme recipe CSS.
'use client';
import { useId, useState } from 'react';
import { Slider } from '@/components/ui/yads-slider';
export default function CustomSliderExample() {
Accessibility
- Name every thumb. Use a visible title and aria-labelledby for a single thumb. For a range, supply distinct thumbLabels such as “Minimum price” and “Maximum price”; a Root label alone does not name Radix thumbs. Explicit thumbLabels overrides inherited naming, including aria-labelledby. Fallbacks are “Value”, “Minimum”/“Maximum”, or “Value 1”, “Value 2”, etc. Localize them via thumbLabels.
- Show the value and context. Connect help/error IDs with aria-describedby; YADS forwards them to every thumb. Application-owned aria-invalid only conveys state; Slider does not validate, block submission, generate errors or expose required/readOnly text-input semantics. Include units in visible feedback.
- Keep keyboard access. Tab reaches enabled thumbs individually; arrow keys adjust one step, Page Up/Down and Shift+arrows ten steps. Home moves the first thumb to min; End moves the last to max, even if another thumb has focus. Bounds, minimum gaps, direction and inversion constrain movement. Vertical Up increases by default. A two-pixel focus outline remains visible in both themes.
- Touch and forms. The 44px track area and extended thumb hit targets support pointer/touch dragging. Test with your assistive technology: touch screen readers can have slider gesture limitations. Disabled thumbs cannot be edited but named values still submit in tested Radix 1.6.1; filter application serialization or omit the slider when exclusion is needed.
API reference
Import { Slider, type SliderProps } from @/components/ui/yads-slider. A thin @radix-ui/react-slider Root/Track/Range/Thumb composition; Root span props and events pass through. Fixed children mean children/asChild are excluded. There are no tooltips, field wrappers, validation or nonlinear scales.
On narrow screens, focus the table and scroll horizontally to read all columns.
| Prop | Type | Default | Description |
|---|---|---|---|
value / defaultValue | number[] | Uncontrolled: [min] | One thumb per array entry. Use [40] for one value, [20, 80] for a range. Supply ordered, in-bounds step-aligned values. Explicit arrays, including [], are honored. Do not combine controlled and uncontrolled usage. |
onValueChange / onValueCommit | (values: number[]) => void | Not set | Change follows each adjustment; commit reports changed values after pointer release or keyboard adjustment. Controlled consumers update value in onValueChange. |
min / max / step | number | 0 / 100 / 1 | Linear bounds and step size. Use min < max and a positive step; initial values are the application’s responsibility. |
minStepsBetweenThumbs | number | 0 | Minimum gap in steps, not raw units: step=10 and minStepsBetweenThumbs=2 requires a gap of 20. |
preserveThumbOrder | boolean | false (Radix) | False allows crossing and sorts values. True constrains each thumb to its neighbors; useful for stable minimum/maximum roles. |
disabled | boolean | false | Prevents pointer/keyboard editing and skips Tab. Named disabled sliders still serialize in tested Radix 1.6.1. Not native input exclusion. |
orientation / dir / inverted | horizontal | vertical / ltr | rtl / boolean | horizontal / ltr / false | Radix direction and orientation semantics; set dir for RTL (or use Radix DirectionProvider). Vertical has a scoped 12rem default height; change it with style or className. |
name / form | string | Not set | Hidden form inputs: name for single, repeated name[] for ranges. form associates an external form by ID. Unnamed sliders are not serialized. |
thumbLabels | string[] | Value; Minimum/Maximum; Value N | Names by rendered thumb index. Each provided entry overrides root aria-label AND aria-labelledby on that thumb. Use nonempty, distinct contextual names for ranges. |
aria-label / aria-labelledby | string | Not set on root | Single thumb inherits root naming unless thumbLabels overrides it. Multiple thumbs use thumbLabels or distinct fallbacks, not a shared root name. Root ARIA remains unchanged. |
aria-describedby / aria-invalid / aria-valuetext | Native ARIA values | Not set | Also forwarded to every thumb. Application supplies descriptions, errors and value text; no validation or error styling is generated. For different numeric values, prefer native numeric announcements over a shared aria-valuetext. |
className / style / ref | string / CSSProperties / Ref<HTMLSpanElement> | Not set | Scoped class is preserved. Ref points to Root span, not an input or thumb. Query a role=slider descendant to focus a thumb if needed. |
Form reset and supported props
Radix 1.6.1 restores the initial value array on native form reset and calls onValueChange when the value changes. Controlled consumers must accept that update or reset their state themselves. Unlike a native range input, this component is a span with ARIA slider thumbs and hidden form inputs. Root id, data attributes, ARIA and event handlers remain supported; native input constraints and selection methods are not.
Playground defaults
Reset restores one enabled horizontal thumb at 40%, min 0, max 100, step 5. Range starts at 25–75%. These are example choices, not primitive defaults: without value/defaultValue, Slider starts with one thumb at min (0 by default).