Multi Range
<sl-multi-range> | SlMultiRange
Multi-Ranges allow the user to select multiple values within a given range using a slider with multiple handles.
<sl-multi-range></sl-multi-range>
import SlRange from '@shoelace-style/shoelace/dist/react/multi-range'; const App = () => <SlRange />;
Examples
Min, Max, and Step
Use the min
and max
attributes to set the range’s minimum and maximum values,
respectively. The step
attribute determines the value’s interval when increasing and
decreasing.
<sl-multi-range min="1" max="10" step="1" value="0,10"></sl-multi-range>
import SlRange from '@shoelace-style/shoelace/dist/react/multi-range'; const App = () => <SlRange min={1} max={10} step={1} value={'0,10'}/>;
Disabled
Use the disabled
attribute to disable a slider.
<sl-multi-range disabled></sl-multi-range>
import SlRange from '@shoelace-style/shoelace/dist/react/multi-range'; const App = () => <SlRange disabled />;
Arbitrary Number of Handles
You can use any number of handles on the slider. The slider will have one handle for every element in the value array.
<sl-multi-range value="25,50,75"></sl-multi-range>
import SlRange from '@shoelace-style/shoelace/dist/react/multi-range'; const App = () => <SlRange value={'25,50,75'} />;
Label and Help Text
You can add an accessible label and/or descriptive help text using the label
and
help-text
attributes or slots.
<sl-multi-range label="Difficulty Range" help-text="Search for challenges within the desired difficulty range"></sl-multi-range>
import SlRange from '@shoelace-style/shoelace/dist/react/multi-range'; const App = () => <SlRange label="Difficulty Range" help-text="Search for challenges within the desired difficulty range" />;
Custom Track Colors
You can customize the active and inactive portions of the track using the
--track-color-active
and --track-color-inactive
custom properties.
<sl-multi-range value="25,75" style=" --track-color-active: var(--sl-color-green-300); --track-color-inactive: var(--sl-color-red-300); " ></sl-multi-range>
import SlRange from '@shoelace-style/shoelace/dist/react/multi-range'; const App = () => <SlRange value={'25,75'} style={{ '--track-color-active': 'var(--sl-color-green-300)', '--track-color-inactive': 'var(--sl-color-red-300)' }}/>;
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component from the CDN using a script tag:
<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.14.0/cdn/components/multi-range/multi-range.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.14.0/cdn/components/multi-range/multi-range.js';
To import this component using a bundler:
import '@shoelace-style/shoelace/dist/components/multi-range/multi-range.js';
To import this component as a React component:
import SlMultiRange from '@shoelace-style/shoelace/dist/react/multi-range';
Slots
Name | Description |
---|---|
label
|
The range’s label. Alternatively, you can use the label attribute. |
help-text
|
Text that describes how to use the input. Alternatively, you can use the
help-text attribute.
|
Learn more about using slots.
Properties
Name | Description | Reflects | Type | Default |
---|---|---|---|---|
label
|
The range’s label. If you need to display HTML, use the label slot instead. |
string
|
''
|
|
helpText
help-text
|
The range’s help text. If you need to display HTML, use the help-text slot instead. |
string
|
''
|
|
disabled
|
Disables the range. |
|
boolean
|
false
|
min
|
The minimum acceptable value of the range. |
number
|
0
|
|
max
|
The maximum acceptable value of the range. |
number
|
100
|
|
step
|
The interval at which the range will increase and decrease. |
number
|
1
|
|
tooltip
|
The preferred placement of the range’s tooltip. |
'top' | 'bottom' | 'none'
|
'top'
|
|
value
|
The current values of the input (in ascending order) as a string of comma-separated values | - | - | |
valueAsArray
|
Gets of sets the current values of the range as an array of numbers | - | - | |
tooltipFormatter
|
A function used to format the tooltip’s value. The range’s value is passed as the first and only argument. The function should return a string to display in the tooltip. |
(value: number) => string
|
- | |
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Events
Name | React Event | Description | Event Detail |
---|---|---|---|
sl-blur |
onSlBlur |
Emitted when the control loses focus. | - |
sl-change |
onSlChange |
Emitted when an alteration to the control’s value is committed by the user. | - |
sl-focus |
onSlFocus |
Emitted when the control gains focus. | - |
sl-input |
onSlInput |
Emitted when the control receives input. | - |
Learn more about events.
Custom Properties
Name | Description | Default |
---|---|---|
--thumb-size |
The size of the thumb. | |
--tooltip-offset |
The vertical distance the tooltip is offset from the track. | |
--track-color-active |
The color of the portion of the track that represents the current value. | |
--track-color-inactive |
The of the portion of the track that represents the remaining value. | |
--track-height |
The height of the track. |
Learn more about customizing CSS custom properties.