Slider
A slider is a UI element that lets users select a single value or a range of values along a bar.
Slider API
Import
import { Slider } from '@mui/base/Slider';
// or
import { Slider } from '@mui/base';
Props of the native component are also available.
A string value that provides a user-friendly name for the current value of the slider.
Type:string
If true
, the active thumb doesn't swap when moving pointer over a thumb while dragging another thumb.
Type:bool
Default:false
Accepts a function which returns a string value that provides a user-friendly name for the thumb labels of the slider. This is important for screen reader users.
Type:func
function(index: number) => string
index
The thumb label's index to format.
Accepts a function which returns a string value that provides a user-friendly name for the current value of the slider. This is important for screen reader users.
Type:func
function(value: number, index: number) => string
value
The thumb label's value to format.index
The thumb label's index to format.
If true
the Slider will be rendered right-to-left (with the lowest value on the right-hand side).
Type:bool
Default:false
Marks indicate predetermined values to which the user can move the slider. If true
the marks are spaced according the value of the step
prop. If an array, it should contain objects with value
and an optional label
keys.
Type:Array<{ label?: node, value: number }>
| bool
Default:false
Callback function that is fired when the slider's value changed.
Type:func
function(event: Event, value: number | Array, activeThumb: number) => void
event
The event source of the callback. You can pull out the new value by accessingevent.target.value
(any). Warning: This is a generic event not a change event.value
The new value.activeThumb
Index of the currently moved thumb.
Callback function that is fired when the mouseup
is triggered.
Type:func
function(event: React.SyntheticEvent | Event, value: number | Array) => void
event
The event source of the callback. Warning: This is a generic event not a change event.value
The new value.
A transformation function, to change the scale of the slider.
Type:func
Default:function Identity(x) {
return x;
}
function(x: any) => any
The props used for each slot inside the Slider.
Type:{ input?: func
| object, mark?: func
| object, markLabel?: func
| object, rail?: func
| object, root?: func
| object, thumb?: func
| object, track?: func
| object, valueLabel?: any
| func }
Default:{}
The components used for each slot inside the Slider. Either a string to use a HTML element or a component.
See Slots API below for more details.
Type:{ input?: elementType, mark?: elementType, markLabel?: elementType, rail?: elementType, root?: elementType, thumb?: elementType, track?: elementType, valueLabel?: elementType }
Default:{}
The granularity with which the slider can step through values. (A "discrete" slider.) The min
prop serves as the origin for the valid values. We recommend (max - min) to be evenly divisible by the step.
When step is null
, the thumb can only be slid onto marks provided with the marks
prop.
Type:number
Default:1
The track presentation:
normal
the track will render a bar representing the slider value.inverted
the track will render a bar representing the remaining slider value.false
the track will render without a bar.
Type:'inverted'
| 'normal'
| false
Default:'normal'
The value of the slider. For ranged sliders, provide an array with two values.
Type:Array<number>
| number
ref
is forwarded to the root element.To learn how to customize the slot, check out the Overriding component structure guide.
The component that renders the mark label.
Class name: .MuiSlider-markLabel
Default component: 'span'
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
Class name applied to the root element if marks
is provided with at least one label.
Class name applied to the mark label element if active (depending on the value).