Slider API
The API documentation of the Slider React component. Learn more about the properties and the CSS customization points.
import Slider from '@material-ui/core/Slider';
Props
Name | Type | Default | Description |
---|---|---|---|
aria-label | string | The label of the slider. | |
aria-labelledby | string | The id of the element containing a label for the slider. | |
aria-valuetext | string | A string value that provides a user-friendly name for the current value of the slider. | |
classes | object | Override or extend the styles applied to the component. See CSS API below for more details. | |
component | elementType | 'span' | The component used for the root node. Either a string to use a DOM element or a component. |
defaultValue | union: number | arrayOf |
The default element value. Use when the component is not controlled. | |
disabled | bool | false | If true , the slider will be disabled. |
getAriaValueText | func | Accepts a function which returns a string value that provides a user-friendly name for the current value of the slider. Signature: function(value: number, index: number) => void value: The thumb label's value to format index: The thumb label's index to format |
|
marks | union: bool | array |
[] | Marks indicate predetermined values to which the user can move the slider. If true the marks will be spaced according the value of the step prop. If an array, it should contain objects with value and an optional label keys. |
max | number | 100 | The maximum allowed value of the slider. Should not be equal to min. |
min | number | 0 | The minimum allowed value of the slider. Should not be equal to max. |
name | string | Name attribute of the hidden input element. |
|
onChange | func | Callback function that is fired when the slider's value changed. Signature: function(event: object, value: any) => void event: The event source of the callback value: The new value |
|
onChangeCommitted | func | Callback function that is fired when the mouseup is triggered.Signature: function(event: object, value: any) => void event: The event source of the callback value: The new value |
|
orientation | enum: 'horizontal' | 'vertical' |
'horizontal' | The slider orientation. |
step | number | 1 | The granularity with which the slider can step through values. (A "discrete" slider.) When step is null , the thumb can only be slid onto marks provided with the marks prop. |
ThumbComponent | elementType | 'span' | The component used to display the value label. |
value | union: number | arrayOf |
The value of the slider. For ranged sliders, provide an array with two values. | |
ValueLabelComponent | elementType | ValueLabel | The value label componnet. |
valueLabelDisplay | enum: 'on' | 'auto' | 'off' |
'off' | Controls when the value label is displayed: - auto the value label will display when the thumb is hovered or focused. - on will display persistently. - off will never display. |
valueLabelFormat | union: string | func |
x => x | The format function the value label's value. When a function is provided, it should have the following signature: - {number} value The value label's value to format - {number} index The value label's index to format |
The ref
is forwarded to the root element.
Any other properties supplied will be provided to the root element (native element).
CSS
You can override all the class names injected by Material-UI thanks to the classes
prop.
This prop accepts the following keys:
Name | Description |
---|---|
root | Styles applied to the root element. |
marked | Styles applied to the root element if marks is provided with at least one label. |
vertical | Pseudo-class applied to the root element if orientation="vertical" . |
disabled | Pseudo-class applied to the root element if disabled={true} . |
rail | Styles applied to the rail element. |
track | Styles applied to the track element. |
thumb | Styles applied to the thumb element. |
active | Pseudo-class applied to the thumb element if it's active. |
focusVisible | Pseudo-class applied to the thumb element if keyboard focused. |
valueLabel | Styles applied to the thumb label element. |
mark | Styles applied to the mark element. |
markActive | Styles applied to the mark element if active (depending on the value). |
markLabel | Styles applied to the mark label element. |
markLabelActive | Styles applied to the mark label element if active (depending on the value). |
Have a look at the overriding styles with classes section and the implementation of the component for more detail.
If using the overrides
key of the theme,
you need to use the following style sheet name: MuiSlider
.
Notes
The component is fully StrictMode compatible.