2.2.0
Range Sliders select a numeric value, or range of values, by moving a handle, or set of handles, along a bar.
Use when soliciting a single numeric value.
<div class="mds-range-slider__group">
<div class="mds-range-slider__input-wrapper">
<label class="mds-form__label" for="slider_number_field_1">
Years
</label>
<input class="mds-form__input mds-range-slider__input" type="number" id="slider_number_field_1" min="0" max="100">
</div>
<div class="mds-range-slider__wrapper">
<div id="slider_input" class="mds-range-slider" role="slider" aria-orientation="horizontal" aria-valuemin="0.0" aria-valuemax="100.0" aria-valuenow="20.0" aria-valuetext="20">
<!-- This markup is dynamically created by the noUiSlider JS Library -->
</div>
</div>
</div>
<div class="mds-range-slider__group">
<div class="mds-range-slider__input-wrapper">
<label class="mds-form__label" for="slider_number_field_2">
Years
</label>
<input class="mds-form__input mds-range-slider__input" type="number" id="slider_number_field_2" min="0" max="100" disabled>
</div>
<div class="mds-range-slider__wrapper">
<div id="slider_input_disabled" disabled class="mds-range-slider" role="slider" aria-orientation="horizontal" aria-valuemin="0.0" aria-valuemax="100.0" aria-valuenow="20.0" aria-valuetext="20">
<!-- This markup is dynamically created by the noUiSlider JS Library -->
</div>
</div>
</div>
div
with a unique ID, i.e., <div id="[mySliderDivId]" disabled>
.<input id="[myInputId]" disabled>
.Use when soliciting a range between two numeric values.
<div class="mds-range-slider__group--min-max">
<div class="mds-range-slider__input-wrapper">
<label class="mds-form__label" for="slider_two_number_field_min_1">
Minimum Value
</label>
<input class="mds-form__input mds-range-slider__input mds-range-slider__input--min" type="number" id="slider_two_number_field_min_1" min="0" max="100">
</div>
<div class="mds-range-slider__wrapper">
<div id="slider_two_with_input" class="mds-range-slider">
<!-- This markup is dynamically created by the noUiSlider JS Library -->
</div>
</div>
<div class="mds-range-slider__input-wrapper">
<label class="mds-form__label" for="slider_two_number_field_max_1">
Maximum Value
</label>
<input class="mds-form__input mds-range-slider__input mds-range-slider__input--max" type="number" id="slider_two_number_field_max_1" min="0" max="100">
</div>
</div>
<div class="mds-range-slider__group--min-max">
<div class="mds-range-slider__input-wrapper">
<label class="mds-form__label" for="slider_two_number_field_min_2">
Minimum Value
</label>
<input class="mds-form__input mds-range-slider__input mds-range-slider__input--min" type="number" id="slider_two_number_field_min_2" min="0" max="100" disabled>
</div>
<div class="mds-range-slider__wrapper">
<div id="slider_two_with_input_disabled" disabled class="mds-range-slider">
<!-- This markup is dynamically created by the noUiSlider JS Library -->
</div>
</div>
<div class="mds-range-slider__input-wrapper">
<label class="mds-form__label" for="slider_two_number_field_max_2">
Maximum Value
</label>
<input class="mds-form__input mds-range-slider__input mds-range-slider__input--max" type="number" id="slider_two_number_field_max_2" min="0" max="100" disabled>
</div>
</div>
div
with a unique ID, i.e., <div id="[mySliderDivId]" disabled>
.<input id="[myInputId]" disabled>
.<div id="[mySliderDivId]"></div>
element as it will break the rendering. Any widths to control the range slider must be set on its parent element.grab
cursor; clicking will change to the grabbing
cursor.aria
and role
attributes for the sliders. When using the noUiSlider library these attributes are added automatically. See Mozilla’s slider accessibility documentation for details.min
and max
attributes for Form Text Boxes.label
elements with slider input fields. If no labels are desired, use the mds-doc-screenreader-only
class to visually hide the labels while preserving accessibility.
Class
|
Applies to
|
Outcome
|
---|---|---|
|
|
Handles width and positioning of the slider bar. |
|
|
Handles width and positioning of the |
|
|
Hides the slider bar. |
|
|
Sets a |
The System’s range sliders depend on the noUiSlider (^10.1.0) third-party JavaScript library, offered via the MDS Node Package. If you are not using MDS through our Node package, you can download noUiSlider separately.
You can review the noUiSlider documentation to see what options are available.
When initializing a range slider, you must use noUiSlider's cssClasses
and cssPrefix
options to apply the correct MDS CSS styles.
Copy this code in to your codebase to create the mdsRangeSliderClassOverrides
variable, which maps all noUiSlider styles to relevant MDS BEM classes:
// Class overrides to follow BEM conventions in MDS
const mdsRangeSliderClassOverrides = {
'target': '__target',
'base': '__base',
'origin': '__origin',
'handle': '__handle',
'handleLower': '__handle--lower',
'handleUpper': '__handle--upper',
'horizontal': '--horizontal',
'vertical': '--vertical',
'background': '__background',
'connect': '__connect',
'ltr': '--ltr',
'rtl': '--rtl',
'draggable': '--draggable',
'drag': '--state-drag',
'tap': '--state-tap',
'active': '--active',
'tooltip': '__tooltip',
'pips': '__pips',
'pipsHorizontal': '__pips--horizontal',
'pipsVertical': '__pips--vertical',
'marker': '__marker',
'markerHorizontal': '__marker--horizontal',
'markerVertical': '__marker--vertical',
'markerNormal': '__marker--normal',
'markerLarge': '__marker--large',
'markerSub': '__marker--sub',
'value': '__value',
'valueHorizontal': '__value--horizontal',
'valueVertical': '__value-vertical',
'valueNormal': '__value-normal',
'valueLarge': '__value-large',
'valueSub': '__value-sub'
};
When initializing a range slider, use the cssPrefix
and cssClasses
options to apply MDS styles:
// Initalize a range slider with class overrides
const mySlider = document.getElementById('mySliderId');
noUiSlider.create(mySlider, {
...
cssPrefix: 'mds-range-slider',
cssClasses: mdsRangeSliderClassOverrides,
...
});