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.

30
trackStyle 
thumbStyle 
size 
labelPosition 
labelAlign 
isEmphasized 
isDisabled 
import {Slider} from '@react-spectrum/s2';

<Slider label="Cookies" defaultValue={30} />

Controlled

25

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.

50
 
 
 
formatOptions 
<Slider
  label="Amount"
  maxValue={150}
  defaultValue={50}
  step={5} />

Props

NameTypeDefault
fillOffsetnumberDefault:
The offset from which to start the fill.
size'S''M''L''XL'Default: 'M'
The size of the Slider.
isEmphasizedbooleanDefault:
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.
isDisabledbooleanDefault:
Whether the whole Slider is disabled.
stylesDefault:
Spectrum-defined styles, returned by the style() macro.
valueTDefault:
The current value (controlled).
defaultValueTDefault:
The default value (uncontrolled).
onChange(value: T) => voidDefault:
Handler that is called when the value changes.
onChangeEnd(value: T) => voidDefault:
Fired when the slider stops moving, due to being let go.
formatOptionsIntl.NumberFormatOptionsDefault:
The display format of the value label.