Slider
Sliders allow users to quickly select a value within a range. They should be used when the upper and lower bounds to the range are invariable.
trackStyle
thumbStyle
size
labelPosition
labelAlign
isEmphasized
isDisabled
Controlled
Current value: 25
Last value: 25
import {Slider} from '@react-spectrum/s2';
import {useState} from 'react';
function Example() {
let [value, setValue] = useState(25);
let [lastValue, setLastValue] = useState(value);
return (
<>
<Slider
label="Cookies to buy"
value={value}
onChange={setValue}
onChangeEnd={setLastValue} />
<p>Current value: {value}</p>
<p>Last value: {lastValue}</p>
</>
);
}
Value scale
By default, slider values are percentages between 0 and 100. A different scale can be used by setting the minValue
and maxValue
props.
The step
prop can be used to snap the value to certain increments. The steps are calculated
starting from the minimum. For example, if minValue={2}
, and step={3}
, the valid step values would be 2, 5, 8, 11, etc.
formatOptions
The display format of the value label.
formatOptions
Props
Name | Type | Default |
---|---|---|
fillOffset | number | Default: — |
The offset from which to start the fill. | ||
size | 'S'
| 'M'
| 'L'
| 'XL' | Default: 'M'
|
The size of the Slider. | ||
isEmphasized | boolean | Default: — |
Whether the Slider should be displayed with an emphasized style. | ||
trackStyle | 'thin' | 'thick' | Default: 'thin'
|
The style of the Slider's track. | ||
thumbStyle | 'default' | 'precise' | Default: 'default'
|
The style of the Slider's thumb. | ||
isDisabled | boolean | Default: — |
Whether the whole Slider is disabled. | ||
styles | StylesProp | Default: — |
Spectrum-defined styles, returned by the style() macro. | ||
value | T | Default: — |
The current value (controlled). | ||
defaultValue | T | Default: — |
The default value (uncontrolled). | ||
onChange |
| Default: — |
Handler that is called when the value changes. | ||
onChangeEnd |
| Default: — |
Fired when the slider stops moving, due to being let go. | ||
formatOptions | Intl.NumberFormatOptions | Default: — |
The display format of the value label. | ||