Beta Preview

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 
formatOptions 
contextualHelp 
isEmphasized 
isDisabled 
import {Slider} from '@react-spectrum/s2';

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

Value

Use the value or defaultValue prop to set the slider's value. The onChange event is called as the user drags, and onChangeEnd is called when the thumb is released.

25
onChange value: 25
onChangeEnd value: 25
import {Slider} from '@react-spectrum/s2';
import {useState} from 'react';

function Example() {
  let [currentValue, setCurrentValue] = useState(25);
  let [finalValue, setFinalValue] = useState(currentValue);

  return (
    <>
      <Slider
        label="Cookies to buy"
        value={currentValue}
        onChange={setCurrentValue}
        onChangeEnd={setFinalValue} />
      <pre style={{fontSize: 12}}>
        onChange value: {currentValue}{'\n'}
        onChangeEnd value: {finalValue}
      </pre>
    </>
  );
}

Value scale

By default, slider values are percentages between 0 and 100. Use the minValue, maxValue, and step props to set the allowed values. 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
 
 
 
 
<Slider
  label="Amount"
  maxValue={150}
  defaultValue={50}
  step={5}
  fillOffset={75} />

API

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.