Selection
Slider
A slider sets a number in a known range by dragging, tapping or the arrow keys, such as the length of a session, and always shows the value in text.
In kanso-ui as Slider
Web and native
Slider in kanso-ui 0.59.0, for React.
import { Slider } from '@kanso-labs/kanso-ui'A slider for one value, or for a range when the value is a pair.
It follows the Material Design slider: a track split into an active part in primary and an inactive part in secondary container, with a 4dp-wide handle and 6dp of space either side of it. While a handle is dragged or has keyboard focus, a value indicator above it shows what the slider announces.
What you provide
label: what the slider sets. A slider labelled some other way leaves it out and passesaria-labelinstead.- For a range, a pair as
valueordefaultValue, andthumbLabelsto name each handle.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
icon | ReactNode | — | Deprecated: Kanso's 6px track has no room for an icon inset in it. It is not drawn, and warns once in development. |
label | string | — | What the slider sets. A slider that a row labels some other way leaves it out and passes `aria-label` instead. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | Along which axis the handle moves. A vertical slider is 240px tall until `style` on the root says otherwise. |
showStops | boolean | false | A stop at every step, so the reader can see where the thumb can land. Meant for a slider with a handful of steps: each stop is a 4px dot, and a fine step draws a crowd of them. |
size | 'lg' | 'md' | 'sm' | 'xl' | 'xs' | 'xs' | Kanso's slider has one size, `xs`: a 6px track and a 24px thumb in a 48px row. `sm`, `md`, `lg` and `xl` are deprecated; each draws `xs` and warns once in development. |
thumbLabels | string[] | — | A name for each thumb of a range slider, in order, since two thumbs named by the same label cannot be told apart. |
Also takes the props of Omit<SliderProps$1, 'children' | 'orientation'>.
Example
import { Slider } from '@kanso-labs/kanso-ui'
<Slider label="Label" defaultValue={40} />
<Slider label="Label" defaultValue={[20, 60]} thumbLabels={['Start', 'End']} />
<Slider label="In steps of ten" defaultValue={40} step={10} showStops />The design’s classes
k-slider, k-slider__head, k-slider__value, and --k-fill on the input: the filled share as a percentage, from which Chromium and Safari paint the fill (Firefox uses ::-moz-range-progress).
Slider in kanso-ui and react-native-kanso-ui, restyled to this language.