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>
.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.
The noUiSlider library enables MDS to retain its class-naming structure with the cssClasses
option. MDS exposes a JavaScript bemClassOverrides
object within mds/dist/assets/scripts/mds_library.js
(post-compile). It is a requirement to set the cssClasses: bemClassOverrides
option each time a noUiSlider.create()
function is called.
To generate a range slider:
<div id="mySliderId">
element in the DOM. The noUiSlider.create()
function must target the ID attribute set on an empty <div>
.noUiSlider.create()
with your empty div
ID as the first parameter and the slider options array as the second parameter.input
to bind a slider with the input
as a mutual dependency.Notes About Markup Structure
There are no layout requirements for a slider with input
s. The markup requirements are:
<div id="mySliderId"></div>
<input id="myInputId">
s bound to the sliderThe inline layouts in the slider examples are included with MDS.
A range slider will fill out 100% of the width of its container. Do not set an explicit width on the <div id="mySliderId"></div>
element as it will break the rendering. Any widths to control the range slider must be set on its parent element.