Slider
A slider is a UI element that lets users select a single value or a range of values along a bar.
useSlider API
Import
import { useSlider } from '@mui/base/useSlider';
// or
import { useSlider } from '@mui/base';Learn about the difference by reading this guide on minimizing bundle size.
| Name | Type | Default | Description |
|---|---|---|---|
| aria-labelledby | string | - | The id of the element containing a label for the slider. |
| defaultValue | number | ReadonlyArray<number> | - | The default value. Use when the component is not controlled. |
| disabled | boolean | false | If |
| disableSwap | boolean | false | If |
| isRtl | boolean | false | If |
| marks | boolean | ReadonlyArray<Mark> | 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 | (event: Event, value: number | number[], activeThumb: number) => void | - | Callback function that is fired when the slider's value changed. |
| onChangeCommitted | (event: React.SyntheticEvent | Event, value: number | number[]) => void | - | Callback function that is fired when the |
| orientation | 'horizontal' | 'vertical' | 'horizontal' | The component orientation. |
| rootRef | React.Ref<Element> | - | The ref attached to the root of the Slider. |
| scale | (value: number) => number | function Identity(x) { return x; } | A transformation function, to change the scale of the slider. |
| shiftStep | number | 10 | The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down. |
| step | number | null | 1 | The granularity with which the slider can step through values. (A "discrete" slider.) The |
| tabIndex | number | - | Tab index attribute of the hidden |
| value | number | ReadonlyArray<number> | - | The value of the slider. For ranged sliders, provide an array with two values. |
| Name | Type | Description |
|---|---|---|
| active | number | The active index of the slider. |
| axis | Axis | The orientation of the slider. |
| axisProps | { [key in Axis]: AxisProps<key> } | Returns the |
| dragging | boolean | If |
| focusedThumbIndex | number | The index of the thumb which is focused on the slider. |
| getHiddenInputProps | <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSliderHiddenInputProps<ExternalProps> | Resolver for the hidden input slot's props. |
| getRootProps | <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSliderRootSlotProps<ExternalProps> | Resolver for the root slot's props. |
| getThumbProps | <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseSliderThumbSlotProps<ExternalProps> | Resolver for the thumb slot's props. |
| getThumbStyle | (index: number) => object | Resolver for the thumb slot's style prop. |
| marks | Mark[] | The marks of the slider. Marks indicate predetermined values to which the user can move the slider. |
| open | number | The thumb index for the current value when in hover state. |
| range | boolean | If |
| rootRef | React.RefCallback<Element> | null | Ref to the root slot's DOM node. |
| trackLeap | number | The track leap for the current value of the slider. |
| trackOffset | number | The track offset for the current value of the slider. |
| values | number[] | The possible values of the slider. |