A track with a thumb to drag for a number or a range.
import { Slider } from '@oztix/roadie-components/slider'
Pass a label and a defaultValue. The value shows beside the label.
<Slider label='Volume' defaultValue={40} />
Pass an array for a range. Each value gets its own thumb. format takes Intl.NumberFormat options, so a price reads in dollars. Values format in en-AU unless you pass a locale.
Use a unit format for distances, durations and sizes.
step snaps the value, and largeStep sets the jump for Page Up, Page Down and Shift with an arrow key. For tick marks, compose the parts and place each mark along the track as a percentage.
Leave out label for a bare track, such as a volume control in a player. Give it an aria-label instead.
<Slider aria-label='Volume' defaultValue={60} />
Set direction='vertical' for a slider that runs up the page.
<Slider aria-label='Stage monitor level' direction='vertical' defaultValue={70} />
size scales the thumb and track. Every size keeps a 44px touch target.
<div className='grid gap-4'> <Slider label='Small' size='sm' defaultValue={30} /> <Slider label='Medium' defaultValue={50} /> <Slider label='Large' size='lg' defaultValue={70} /> </div>
Compose the parts to name each thumb, such as the lowest and highest price in a range.
Inside Field, pass label to the slider. It stands in for Field.Label, so the label and value share a line above the track. The slider takes its description from the helper or error text, and invalid and disabled from the field. Clicking the label focuses the first thumb.
onValueChange fires on every step while someone drags. Use onValueCommitted to run a search once they let go.
<Slider label='Price' defaultValue={[40, 150]} max={250} />
Do
Use a slider when close enough is fine and people want to see the range, such as a price filter or a search radius.
<Slider label='Ticket quantity' max={10} />
Don’t
Don't use a slider for an exact number people already know, such as a ticket quantity. Use an input or a select.
Do
Use a slider when people choose the value.
Don’t
Don't use a disabled slider to show a level people can't change, such as capacity sold. Use a Meter.
Do
Keep the value visible beside the label, formatted the way people read it, such as "$40 – $150" or "25 km".
Don’t
Don't make people drag to find out where the thumb is. A bare track needs its value shown somewhere nearby.
input type='range' with role='slider', so it submits with a form and works with assistive tech.label, Slider.Label or Field.Label names the thumbs. For a range, pass aria-label on each Slider.Thumb to tell them apart.format flows into aria-valuetext, so screen readers hear "$40" rather than "40". A range adds "start range" or "end range".Tab moves between thumbs. The arrow keys move by step. Page Up, Page Down and Shift with an arrow key move by largeStep. Home and End jump to the ends.CSS class applied to the element, or a function that returns a class based on the component's state.
The uncontrolled value of the slider when it's initially rendered. To render a controlled slider, use the `value` prop instead.
Identifies the form that owns the slider inputs. Useful when the slider is rendered outside the form.
The granularity with which the slider can step through values. (A "discrete" slider.) The `min` prop serves as the origin for the valid values. We recommend (max - min) to be evenly divisible by the step.
Defaults to 1.
Whether the slider should ignore user interaction.
Defaults to false.
Options to format the value.
The locale used by `Intl.NumberFormat` when formatting the value. Defaults to the user's runtime locale.
Defaults to en-AU.
The maximum allowed value of the slider. Should not be equal to min.
Defaults to 100.
The minimum allowed value of the slider. Should not be equal to max.
Defaults to 0.
The minimum steps between values in a range slider.
Defaults to 0.
Identifies the field when a form is submitted.
The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down.
Defaults to 10.
How the thumb(s) are aligned relative to `Slider.Control` when the value is at `min` or `max`: - `center`: The center of the thumb is aligned with the control edge - `edge`: The thumb is inset within the control such that its edge is aligned with the control edge - `edge-client-only`: Same as `edge` but renders after React hydration on the client, reducing bundle size in return
Defaults to 'center'.
Controls how thumbs behave when they collide during pointer interactions. - `'push'` (default): Thumbs push each other without restoring their previous positions when dragged back. - `'swap'`: Thumbs swap places when dragged past each other. - `'none'`: Thumbs cannot move past each other; excess movement is ignored.
Defaults to 'push'.
The value of the slider. For range sliders, provide an array with one value per thumb.
Callback function that is fired when the slider's value changed. Receives the new value as the first argument; the originating event is available as `eventDetails.event`. The value is also reflected on `eventDetails.event.target.value` for form integration. The `eventDetails.reason` indicates what triggered the change: - `'input-change'` when the hidden range input emits a change event (for example, via form integration) - `'track-press'` when the control track is pressed - `'drag'` while dragging a thumb - `'keyboard'` for keyboard input - `'none'` when the change is triggered without a specific interaction
Callback function that is fired when a value change is committed. Does not fire if the value did not change, or if the change was canceled. **Warning**: This is a generic event, not a change event. The `eventDetails.reason` indicates what triggered the commit: - `'drag'` while dragging a thumb - `'track-press'` when the control track is pressed - `'keyboard'` for keyboard input - `'input-change'` when the hidden range input emits a change event (for example, via form integration) - `'none'` when the commit occurs without a specific interaction
Which way the track runs. `vertical` runs up the page.
Defaults to 'horizontal'.
Defaults to 'md'.
A visible label, with the value shown beside it. Inside `Field` it stands in for `Field.Label`.
Marks the slider invalid. Inherits from `Field` when unset.
No additional props. It forwards all standard HTML attributes to the underlying element.
No additional props. It forwards all standard HTML attributes to the underlying element.
No additional props. It forwards all standard HTML attributes to the underlying element.
CSS class applied to the element, or a function that returns a class based on the component's state.
Inherited from SliderThumbProps
Whether the thumb should ignore user interaction.
Defaults to false.
A string value forwarded to the [`aria-valuetext`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-valuetext) attribute of the `input`. Ignored when `getAriaValueText` is provided.
A function which returns a string value for the [`aria-label`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-label) attribute of the `input`.
A function which returns a string value for the [`aria-valuetext`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-valuetext) attribute of the `input`. This is important for screen reader users.
The index of the thumb which corresponds to the index of its value in the `value` or `defaultValue` array. This prop is required to support server-side rendering for range sliders with multiple thumbs. @example ```tsx <Slider.Root value={[10, 20]}> <Slider.Thumb index={0} /> <Slider.Thumb index={1} /> </Slider.Root> ```
A ref to access the nested input element.
A blur handler forwarded to the `input`.
A focus handler forwarded to the `input`.
A keydown handler forwarded to the `input`.
Optional tab index attribute forwarded to the `input`.
No additional props. It forwards all standard HTML attributes to the underlying element.
No additional props. It forwards all standard HTML attributes to the underlying element.