Provides the behavior and accessibility implementation for a slider component representing one or more values.
import {Slider} from './Slider';
<Slider label="Opacity" defaultValue={60} />
API
<Slider>
<Label />
<SliderOutput />
<SliderTrack>
<SliderFill />
<SliderThumb />
<SliderThumb>
<Label />
</SliderThumb>
</SliderTrack>
</Slider>
useSliderState <T extends number | number [] > (props: SliderStateOptions <T > ): SliderStateuseSlider <T extends number | number [] >(
props: AriaSliderProps <T >,
state: SliderState,
trackRef: RefObject <Element | null >
): SliderAriauseSliderThumb (opts: AriaSliderThumbOptions, state: SliderState ): SliderThumbAriaSliderState
Properties
| Name | Type | |
|---|---|---|
values | number | |
Values managed by the slider by thumb index. | ||
defaultValues | number | |
The default values for each thumb. | ||
focusedThumb | number | undefined | |
Currently-focused thumb index. | ||
pageSize | number | |
The page size for the slider, used to do a bigger step. | ||
orientation | Orientation | |
The orientation of the slider. | ||
isDisabled | boolean | |
Whether the slider is disabled. | ||
Methods
getThumbValue | ||
| Get the value for the specified thumb. | ||
setThumbValue | ||
| Sets the value for the specified thumb. The actual value set will be clamped and rounded according to min/max/step. | ||
setThumbPercent | ||
| Sets value for the specified thumb by percent offset (between 0 and 1). | ||
isThumbDragging | ||
| Whether the specific thumb is being dragged. | ||
setThumbDragging | ||
| Set is dragging on the specified thumb. | ||
setFocusedThumb | ||
| Set focused true on specified thumb. This will remove focus from any thumb that had it before. | ||
getThumbPercent | ||
| Returns the specified thumb's value as a percentage from 0 to 1. | ||
getValuePercent | ||
| Returns the value as a percent between the min and max of the slider. | ||
getThumbValueLabel | ||
| Returns the string label for the specified thumb's value, per props.formatOptions. | ||
getFormattedValue | ||
| Returns the string label for the value, per props.formatOptions. | ||
getThumbMinValue | ||
| Returns the min allowed value for the specified thumb. | ||
getThumbMaxValue | ||
| Returns the max allowed value for the specified thumb. | ||
getPercentValue | ||
| Converts a percent along track (between 0 and 1) to the corresponding value. | ||
isThumbEditable | ||
| Returns if the specified thumb is editable. | ||
setThumbEditable | ||
| Set the specified thumb's editable state. | ||
incrementThumb | ||
| Increments the value of the thumb by the step or page amount. | ||
decrementThumb | ||
| Decrements the value of the thumb by the step or page amount. | ||
AriaSliderProps
| Name | Type | Default |
|---|---|---|
orientation | Orientation | Default: 'horizontal'
|
The orientation of the Slider. | ||
isDisabled | boolean | Default: — |
Whether the whole Slider is disabled. | ||
value | T | Default: — |
The current value (controlled). | ||
defaultValue | T | Default: — |
The default value (uncontrolled). | ||
onChange | | Default: — |
Handler that is called when the value changes. | ||
onChangeEnd | | Default: — |
Fired when the slider stops moving, due to being let go. | ||
SliderAria
| Name | Type | |
|---|---|---|
labelProps | LabelHTMLAttributes | |
Props for the label element. | ||
groupProps | DOMAttributes | |
Props for the root element of the slider component; groups slider inputs. | ||
trackProps | DOMAttributes | |
Props for the track element. | ||
outputProps | OutputHTMLAttributes | |
Props for the output element, displaying the value of the slider thumbs. | ||
AriaSliderThumbOptions
| Name | Type | Default |
|---|---|---|
trackRef | RefObject | Default: — |
A ref to the track element. | ||
inputRef | RefObject | Default: — |
A ref to the thumb input element. | ||
isDisabled | boolean | Default: — |
Whether the Thumb is disabled. | ||
index | number | Default: 0
|
Index of the thumb within the slider. | ||
SliderThumbAria
| Name | Type | |
|---|---|---|
thumbProps | DOMAttributes | |
Props for the root thumb element; handles the dragging motion. | ||
inputProps | InputHTMLAttributes | |
Props for the visually hidden range input element. | ||
labelProps | LabelHTMLAttributes | |
Props for the label element for this thumb (optional). | ||
isDragging | boolean | |
Whether this thumb is currently being dragged. | ||
isFocused | boolean | |
Whether the thumb is currently focused. | ||
isDisabled | boolean | |
Whether the thumb is disabled. | ||