Slider API
Demos
For examples and details on the usage of this React component, visit the component demo pages:
Import
import Slider from '@mui/joy/Slider';
// or
import { Slider } from '@mui/joy';
Name | Type | Default | Description |
---|---|---|---|
aria-label | string | The label of 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. | |
color | 'danger' | 'neutral' | 'primary' | 'success' | 'warning' | string | 'primary' | The color of the component. It supports those theme colors that make sense for this component. To learn how to add your own colors, check out Themed components—Extend colors. |
component | elementType | The component used for the root node. Either a string to use a HTML element or a component. | |
defaultValue | Array<number> | number | The default value. Use when the component is not controlled. | |
disabled | bool | false | If |
disableSwap | bool | false | If |
getAriaLabel | func | 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
| |
getAriaValueText | func | 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
| |
isRtl | bool | false | If |
marks | Array<{ label?: node, value: number }> | bool | false | Marks indicate predetermined values to which the user can move the slider. If |
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 | |
onChange | func | Callback function that is fired when the slider's value changed. Signature: function(event: Event, value: number | Array
| |
onChangeCommitted | func | Callback function that is fired when the Signature: function(event: React.SyntheticEvent | Event, value: number | Array
| |
orientation | 'horizontal' | 'vertical' | 'horizontal' | The component orientation. |
scale | func | function Identity(x) { return x; } | A transformation function, to change the scale of the slider. Signature: function(x: any) => any |
size | 'sm' | 'md' | 'lg' | string | 'md' | The size of the component. It accepts theme values between 'sm' and 'lg'. To learn how to add custom sizes to the component, check out Themed components—Extend sizes. |
slotProps | { input?: func | object, mark?: func | object, markLabel?: func | object, rail?: func | object, root?: func | object, thumb?: func | object, track?: func | object, valueLabel?: func | object } | {} | The props used for each slot inside. |
slots | { input?: elementType, mark?: elementType, markLabel?: elementType, rail?: elementType, root?: elementType, thumb?: elementType, track?: elementType, valueLabel?: elementType } | {} | The components used for each slot inside. See Slots API below for more details. |
step | number | 1 | The granularity with which the slider can step through values. (A "discrete" slider.) The |
sx | Array<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. | |
tabIndex | number | Tab index attribute of the hidden | |
track | 'inverted' | 'normal' | false | 'normal' | The track presentation:
|
value | Array<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:
|
valueLabelFormat | func | string | function Identity(x) { return x; } | The format function the value label's value. |
variant | 'outlined' | 'plain' | 'soft' | 'solid' | string | 'solid' | The global variant to use. To learn how to add your own variants, check out Themed components—Extend variants. |
ref
is forwarded to the root element.Theme default props
You can use JoySlider
to change the default props of this component with the theme.
To learn how to customize the slot, check out the Overriding component structure guide.
Slot name | Class name | Default | Description |
---|---|---|---|
root | .MuiSlider-root | 'span' | The component that renders the root. |
track | .MuiSlider-track | 'span' | The component that renders the track. |
rail | .MuiSlider-rail | 'span' | The component that renders the rail. |
thumb | .MuiSlider-thumb | 'span' | The component that renders the thumb. |
mark | .MuiSlider-mark | 'span' | The component that renders the mark. |
markLabel | .MuiSlider-markLabel | 'span' | The component that renders the mark label. |
valueLabel | .MuiSlider-valueLabel | 'span' | The component that renders the value label. |
input | .MuiSlider-input | 'input' | The component that renders the input. |
These class names are useful for styling with CSS. They are applied to the root slot when specific states are triggered.
Rule name | Description |
---|---|
.Mui-disabled | State class applied to the root and thumb element if disabled={true} . |
.Mui-focusVisible | State class applied to the thumb element if it has keyboard focused. |
.MuiSlider-colorContext | Class name applied to the root element when color inversion is triggered. |
.MuiSlider-colorDanger | Class name applied to the root element if color="danger" . |
.MuiSlider-colorNeutral | Class name applied to the root element if color="neutral" . |
.MuiSlider-colorPrimary | Class name applied to the root element if color="primary" . |
.MuiSlider-colorSuccess | Class name applied to the root element if color="success" . |
.MuiSlider-colorWarning | Class name applied to the root element if color="warning" . |
.MuiSlider-dragging | State class applied to the root if a thumb is being dragged. |
.MuiSlider-markActive | Class name applied to the mark element when it is active. |
.MuiSlider-marked | Class name applied to the root element if marks is provided with at least one label. |
.MuiSlider-sizeLg | Class name applied to the root element if size="lg" . |
.MuiSlider-sizeMd | Class name applied to the root element if size="md" . |
.MuiSlider-sizeSm | Class name applied to the root element if size="sm" . |
.MuiSlider-trackFalse | Class name applied to the root element if track={false} . |
.MuiSlider-trackInverted | Class name applied to the root element if track="inverted" . |
.MuiSlider-valueLabelOpen | Class name applied to the thumb label element if it's open. |
.MuiSlider-variantOutlined | Class name applied to the root element if variant="outlined" . |
.MuiSlider-variantPlain | Class name applied to the root element if variant="plain" . |
.MuiSlider-variantSoft | Class name applied to the root element if variant="soft" . |
.MuiSlider-variantSolid | Class name applied to the root element if variant="solid" . |
.MuiSlider-vertical | Class name applied to the root element if orientation="vertical" . |