Pular para o conteúdo

Slider API

Documentação da API para o componente React Slider . Aprenda sobre as propriedades disponíveis e a API CSS.

Importação

import Slider from '@mui/material/Slider';
// ou
import { Slider } from '@mui/material';
Você pode aprender sobre a diferença lendo este guia sobre como minimizar o tamanho do pacote.

Nome do componente

The name MuiSlider can be used when providing default props or style overrides in the theme.

Propriedades

Propriedades do componente SliderUnstyled também estão disponíveis.

NomeTipoPadrãoDescrição
aria-labelstring
The label of the slider.
aria-labelledbystring
The id of the element containing a label for the slider.
aria-valuetextstring
A string value that provides a user-friendly name for the current value of the slider.
classesobject
Sobrescreve ou extende os estilos aplicados para o componente. Veja a API CSS abaixo para maiores detalhes.
color'primary'
| 'secondary'
| string
'primary'
The color of the component. It supports both default and custom theme colors, which can be added as shown in the palette customization guide.
components{ Input?: elementType, Mark?: elementType, MarkLabel?: elementType, Rail?: elementType, Root?: elementType, Thumb?: elementType, Track?: elementType, ValueLabel?: elementType }{}
The components used for each slot inside the Slider. Either a string to use a HTML element or a component.
defaultValueArray<number>
| number
The default input value. Use when the component is not controlled.
disabledboolfalse
Se true, o componente está desabilitado.
disableSwapboolfalse
If true, the active thumb doesn't swap when moving pointer over a thumb while dragging another thumb.
getAriaLabelfunc
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.

Signature:
function(index: number) => string
index: The thumb label's index to format.
getAriaValueTextfunc
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.

Signature:
function(value: number, index: number) => string
value: The thumb label's value to format.
index: The thumb label's index to format.
isRtlboolfalse
Indicates whether the theme context has rtl direction. It is set automatically.
marksArray<{ label?: node, value: number }>
| bool
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.
maxnumber100
The maximum allowed value of the slider. Should not be equal to min.
minnumber0
The minimum allowed value of the slider. Should not be equal to max.
namestring
Name attribute of the hidden input element.
onChangefunc
Callback function that is fired when the slider's value changed.

Signature:
function(event: object, value: number | number[], activeThumb: number) => void
event: The event source of the callback. You can pull out the new value by accessing event.target.value (any). Warning: This is a generic event not a change event.
value: The new value.
activeThumb: Index of the currently moved thumb.
onChangeCommittedfunc
Callback function that is fired when the mouseup is triggered.

Signature:
function(event: object, value: number | number[]) => void
event: The event source of the callback. Warning: This is a generic event not a change event.
value: The new value.
orientation'horizontal'
| 'vertical'
'horizontal'
The divider orientation.
scalefunc(x) => x
A transformation function, to change the scale of the slider.
size'small'
| 'medium'
| string
'medium'
The size of the slider.
slotProps{ input?: func
| object, mark?: func
| object, markLabel?: func
| object, rail?: func
| object, root?: func
| object, thumb?: func
| object, track?: func
| object, valueLabel?: func
| { children?: element, className?: string, open?: bool, style?: object, value?: number, valueLabelDisplay?: 'auto'
| 'off'
| 'on' } }
{}
slots{ input?: elementType, mark?: elementType, markLabel?: elementType, rail?: elementType, root?: elementType, thumb?: elementType, track?: elementType, valueLabel?: elementType }{}
stepnumber1
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.
sxArray<func
| object
| bool>
| func
| object
The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details.
tabIndexnumber
Tab index attribute of the hidden input element.
track'inverted'
| 'normal'
| false
'normal'
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.
valueArray<number>
| number
The value of the slider. For ranged sliders, provide an array with two values.
valueLabelDisplay'auto'
| 'off'
| 'on'
'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.
valueLabelFormatfunc
| string
(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

O ref é encaminhado para o elemento raiz.

Herança

While not explicitly documented above, the props of the SliderUnstyled component are also available on Slider. You can take advantage of this to target nested components.

CSS

Nome da regraClasse globalDescrição
root.MuiSlider-rootStyles applied to the root element.
marked.MuiSlider-markedClass name applied to o elemento raiz if marks is provided with at least one label.
vertical.MuiSlider-verticalClass name applied to o elemento raiz if orientation="vertical".
disabled.Mui-disabledPseudo-class aplicada a the root and thumb element se disabled={true}.
dragging.MuiSlider-draggingPseudo-class aplicada a the root se a thumb is being dragged.
rail.MuiSlider-railClass name applied to the rail element.
track.MuiSlider-trackClass name applied to the track element.
trackFalse.MuiSlider-trackFalseClass name applied to o elemento raiz if track={false}.
trackInverted.MuiSlider-trackInvertedClass name applied to o elemento raiz if track="inverted".
thumb.MuiSlider-thumbClass name applied to the thumb element.
active.Mui-activePseudo-class aplicada a the thumb element se it's active.
focusVisible.Mui-focusVisiblePseudo-class aplicada a the thumb element se teclado focado.
valueLabel.MuiSlider-valueLabelClass name applied to the thumb label element.
valueLabelOpen.MuiSlider-valueLabelOpenClass name applied to the thumb label element if it's open.
valueLabelCircle.MuiSlider-valueLabelCircleClass name applied to the thumb label's circle element.
valueLabelLabel.MuiSlider-valueLabelLabelClass name applied to the thumb label's label element.
mark.MuiSlider-markClass name applied to the mark element.
markActive.MuiSlider-markActiveClass name applied to the mark element if active (depending on the value).
markLabel.MuiSlider-markLabelClass name applied to the mark label element.
markLabelActive.MuiSlider-markLabelActiveClass name applied to the mark label element if active (depending on the value).
colorPrimary.MuiSlider-colorPrimaryClass name applied to o elemento raiz if color="primary".
colorSecondary.MuiSlider-colorSecondaryClass name applied to o elemento raiz if color="secondary".
sizeSmall.MuiSlider-sizeSmallClass name applied to o elemento raiz if size="small".
thumbColorPrimary.MuiSlider-thumbColorPrimaryClass name applied to the thumb element if color="primary".
thumbColorSecondary.MuiSlider-thumbColorSecondaryClass name applied to the thumb element if color="secondary".
thumbSizeSmall.MuiSlider-thumbSizeSmallClass name applied to the thumb element if size="small".

Você pode sobrescrever o estilo do componente usando uma dessas opções de customização:

Demonstrações