Work with Slider
The Slider API helps you control the component through a set of methods.
Disable and enable Slider
The disable() and enable() methods disable and enable a slider:
// disable a slider on a page
slider.disable();
// make the slider active again
slider.enable();
Related sample: Slider. Disable/enable slider
Check if Slider is disabled
The isDisabled() method checks whether a slider is disabled:
slider.isDisabled(); // -> true/false
Related sample: Slider. Is disabled
Set the value
A user drags the thumb to set the slider value. The setValue() method sets the value from code:
slider.setValue(20);
Related sample: Slider. Set value
Get the value
The getValue() method returns the current value of a slider:
const value = slider.getValue(); // -> [20]
// for a range slider as an array
const value = slider.getValue(); // -> [20,50]
Related sample: Slider. Get value
You can pass an array whose first number is greater than the second one to the setValue() method, for example, [50,20]. In this case, the getValue() method returns the numbers in ascending order, [20,50]:
// sets value as an array (the first number is greater than the second one)
slider.setValue([50,20]);
// returns an array of numbers (the numbers are ascending)
const value = slider.getValue(); // -> [20,50]