Slider
Picks a number, or a range, by dragging a thumb along a scale.
Drag the thumb, or focus it and use the arrow keys. Name a single thumb with aria-label, or put
the slider in a Field. For a range, pass two values and give each thumb its own name.
Dependencies
What it's built from and what's built from it in Mocha, read from the imports in its source.
| Uses | Textprimitive |
|---|---|
| Used by | Nothing yet. |
| Packages | @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20 |
Installation
Set the project up for Mocha once first, as Getting started shows. Then add it with the CLI, or by hand.
With the CLI
Manually
Install its packages:
Add the components it uses first, listed under Dependencies.
Then copy the source:
API reference
Generated from Mocha's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.
Slider
Holds the value. Name a single thumb with a FieldLabel around it, or aria-label on the thumb.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: SliderState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: SliderState) => string)
- controller
Moves the slider from anywhere. Create one with
createSliderController().Type { getValue: () => number | number[]; setValue(value: number | number[], options?: SliderChangeOptions): boolean; focus: (thumb?: number) => void; }
- debug
Logs every state change with its reason to the console, in development builds.
Type boolean
- defaultValue
The value at first, when uncontrolled. A form reset returns to it.
Type number | number[] · Default min
- disabled
Disables it like a native control: thumbs can't be focused or moved, and nothing is submitted.
Type boolean
- form
The id of a form to belong to, when it isn't inside that form.
Type string
- format
How values read, for screen readers and
SliderValue:Intl.NumberFormatoptions, like{ style: "currency", currency: "EUR" }, or a function of the value.Type NumberFormat
- largeStep
How far Page Up, Page Down and Shift with an arrow key move.
Type number · Default 10 steps
- locale
The locale values are formatted in. Defaults to the page's
lang, or the browser's language without one, once the page is interactive. Server markup uses English until then, so it never disagrees with the client.Type string
- max
The highest value. When the steps from
mindon't land on it, the highest step below it is the end.Type number · Default 100
- min
The lowest value.
Type number · Default 0
- minStepsBetweenThumbs
How many steps apart neighbouring thumbs stay. Thumbs never pass each other.
Type number · Default 0
- name
The name it submits under: the number, or a range as
"start/end". Without one, it submits nothing.Type string
- onValueChange
Runs while the value changes: on every step of a drag or a key.
details.thumbsays which thumb moved, anddetails.cancel()stops it.Type (value: number | number[], details: SliderValueChangeDetails) => void
- onValueCommit
Runs once an interaction that changed the value ends: the pointer lifts, the key comes up, or a screen reader adjusts it. For saving.
Type (value: number | number[], details: SliderValueCommitDetails) => void
- orientation
The slider's axis. Vertical sliders grow upward.
Type "horizontal" | "vertical" · Default "horizontal"
- readOnly
Keeps it focusable and submitted, but stops drags, keys and screen reader adjustments from changing it.
Type boolean
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<SliderState>
- required
Marks it required, with
data-required. A slider always has a value, so it never blocks a form.Type boolean
- step
How far one step moves, from
min.Type number · Default 1
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: SliderState) => CSSProperties)
- value
The value: a number for one thumb, or an array with one number per thumb, like
[20, 80]for a range. Pass it to control the slider.Type number | number[]
SliderControl
Where presses land: it moves the nearest thumb there and starts a drag.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: NoInfer<SliderState>) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: NoInfer<SliderState>) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<NoInfer<SliderState>>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: NoInfer<SliderState>) => CSSProperties)
SliderIndicator
Fills the track up to the thumb, or between two.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: NoInfer<SliderState>) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: NoInfer<SliderState>) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<NoInfer<SliderState>>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: NoInfer<SliderState>) => CSSProperties)
SliderThumb
What you drag. Its hidden range input takes focus, so the ring shows on the thumb.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: SliderThumbState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: SliderThumbState) => string)
- index
Which value the thumb shows, from 0. Give each thumb of a range its own.
Type number · Default 0
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<SliderThumbState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: SliderThumbState) => CSSProperties)
SliderTrack
The rail the thumbs move along.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: NoInfer<SliderState>) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: NoInfer<SliderState>) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<NoInfer<SliderState>>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: NoInfer<SliderState>) => CSSProperties)
SliderValue
The formatted value, or a range joined with an en dash.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: SliderValueState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: SliderValueState) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<SliderValueState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: SliderValueState) => CSSProperties)