Sliders
Sliders allow users to select a single value or multiple values from a defined range.
Indeterminate Example
When to Use
- Use an indeterminate slider for subjective settings that focus on intensity rather than a specific value. For example, volume settings or screen brightness.
Examples
Usage
- The lowest value occurs on the left. Greater values progress to the right.
- Labels appear clearly above sliders. Accompanying form fields appear below.
- The slider mechanism and the value displayed in any corresponding input field/s always adjusts interdependently.
Examples
Alternate Indeterminate Slider
When to Use
- Use the alternate indeterminate slider when there are multiple sliders on a screen or panel and/or when there is no need to give visual prominence a slider.
Single Value Text Input Slider Example
A variation of a single input slide, this version allows the user to either enter a value into a text input field, or use the knob to adjust the value. When the user selects the slider control the form field dynamically adjusts in sync with the slider.
When to Use
- Use a single value slider to allow users to specify a single value within a defined range.
Single Integrated Value Example
An integrated slider displays the value of the slider within the slider mechanism itself. This version is preferred in touch contexts. It can also be used when there is limited space and the value itself is not a large number.
When to Use
- Use this version when a specific numeric value is being selected and the when the user may prefer to type in a value.
Multiple Values Slider
When to Use
- Use a dual slider to allow the user to select a specific range from a predetermined set of numerical values.
- Use this version when the user is selecting a lower and upper value to define a range.
Alternate Multiple Values Slider Example
Multiple Range Slider Example
When to Use
- Use a multiple range slider to select two sequential ranges within a specific range of values.
Slider Error Example
Developer Notes
Use of the slider requires a JavaScript helper. It can be instantiated using new Spark.Slider(el)
. Sliders with multiple points can be instantiated using new Spark.RangeSlider(el)
.
Sliders implement the Messaging and Validation mixins, and provide mechanisms for getting and setting their values.
Order Matters
The <input>
element must be before the controls
, otherwise the disabled
state will not work properly.
The following options may be passed when using new Spark.Slider(el, {});
or new Spark.RangeSlider(el, {});
:
For all available methods and full API, refer to the Slider API and Range Slider API documentation.
Indeterminate Slider
Option 1
Option 2
Callback Functions:
- Two provided callback function:
onChange
andonWillChange
. - Callback functions can be configured by parameters in constructor:
var sliderInstance = new Spark.Slider(el, {onChange: function(){...}, onWillChange:function(){...}})
. onChange
will trigger once when finish moving the slider or change the value of input. Arguments ofonChange
will be instance of the slider and current value.onWillChange
will trigger when moving the slider or change the value of input. Arguments ofonWillChange
will be instance of the slider and current value.onWillChange
can have a number return value which will directly set the value of slider afteronWillChange
trigger.
Single Value Slider
Option 1
Option 2
Values greater than 1,000 will be truncated to something like “1k”, but integrated sliders should not be used with numerical values in excess of 3 digits due to space constraints. If you use an integrated slider for large values, don’t expect precise results.
Multiple Values Slider
Option 1
Option 2
The order of the <input>
elements corresponds to the order of the handles, so the first <input>
will be tied to the first element with a class of .spark-slider__handle
. step
will force the slider to move in increments.
Multiple Range Slider
Slider Error Example
Accessibility Notes
Common properties and attributes
The following attributes and properties should be set on the spark-slider__handle
element(s) across all Slider components to ensure that assistive technologies are able to identify the component appropriately and provide meaningful information to users.
- An ARIA
role="slider"
should be set to identify the element as a slider, as this element is the operable control that represents the value of the slider. - The
aria-orientation
property is an optional attribute that can be set on the handle. The value of this will typically behorizontal
, althoughvertical
is an acceptable value if your slider is vertical in nature. Keep in mind that a vertical variation of the Slider is not provided within Spark. If not set the default will behorizontal
. - Use the
aria-valuemin
andaria-valuemax
attributes to indicate to assistive technologies what the minimum and maximum values of the Slider are. The values set should matchmin
andmax
values set on the Slider. - Use the
aria-valuenow
andaria-valuetext
attributes to indicate to assistive technologies what the current value of the Slider is. The values of these attributes should be numerical, and when changed by the user, Javascript will be used to update the attributes with the new values. - If a Slider is disabled, ensure that the
disabled
attribute is present on theinput
element, and that thetabindex="-1"
attribute and value are set on the Slider handle. If the Slider is programmatically disabled or enabled, these attributes will be set or removed using Javascript.
Single Value Sliders
Ensure that the label
element has a unique id
attribute. The value of this attribute should be used as the value of the aria-labelledby
attribute set on the spark-slider__handle
element. This allows the two elements to be connected via the ARIA property and ensures that the label visible on the screen matches with what assistive technologies announces to users. This is also important as a text value is not provided/set on the button
element.
Multiple Value Sliders
This type of Slider utilizes 2 or more Slider handles and input elements, and as such the approach to making this fully accessible is slightly different from the single-value variation.
- Each
input
element should have anaria-label
property set. This is important because each element represents a particular section of the Slider. Anid
should also be set with the value used as the value of thearia-controls
property that is set on the corresponding Slider handle. For assistive technologies that support this feature, this will indicate that the handle and the input are connected and that the button can also control the value of that input. - Each
spark-slider__handle
should also have anaria-label
property set as a text value is not provided/set on thebutton
element.