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.
Variations
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.
Variations
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) or $(el).sparkSlider(). Sliders with multiple points can be instantiated using new Spark.RangeSlider(el) or $(el).sparkRangeSlider().
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, {});, new Spark.Slider(el, {});, $(el).sparkRangeSlider({}); or $(el).sparkRangeSlider({});:
| Name | Type | Default | Description |
|---|---|---|---|
| validate | function | null | A function to run to validate the state of the input. It should call onValidate with the parameters outlined below. |
| onValidate | function | null | A callback function run after validation has completed. Callback arguments are isValid, newValue, instance. |
| onChange | function | null | A callback function run when the input value changes. Callback arguments are newValue, instance. |
| onWillChange | function | null | A callback function run whenver a slider is moved. Callback arguments are newValue, instance. Returning a number from this callback will cause that value to be set instead of whatever is returned by newValue. |
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:
onChangeandonWillChange. - Callback functions can be configured by parameters in constructor:
var sliderInstand = new Spark.Slider(el, {onChange: function(){...}, onWillChange:function(){...}}). onChangewill trigger once when finish moving the slider or change the value of input. Arguments ofonChangewill be instance of the slider and current value.onWillChangewill trigger when moving the slider or change the value of input. Arguments ofonWillChangewill be instance of the slider and current value.onWillChangecan have a number return value which will directly set the value of slider afteronWillChangetrigger.
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 variations to ensure that assistive technologies are able to identify the component appropriately and provide meaningful information to users.
- An ARIA
role="slider"should set to identify the element as a slider, as this element is the operable element that represents the value of the slider. - The
aria-orientationproperty should be set as an attribute of the handle. The value of this will typically behorizontal, althoughverticalis 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. - Use the
aria-valueminandaria-valuemaxattributes to indicate to assistive technologies what the minimum and maximum values of the Slider are. The values set should matchminandmaxvalues set to on the Slider. - Use the
aria-valuenowandaria-valuetextattributes 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
disabledattribute is present on theinputelement, and that thetabindex="-1"attribute and value are set on the Slider handle. If the Slider is programmatically disabled r 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 variation of the 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
inputelement should have anaria-labelproperty set. This is important because each element represents a particular section of the Slider. Anidshould also be set with the value used as the value of thearia-controlsproperty 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__handleshould also have anaria-labelproperty set as a text value is not provided/set on thebuttonelement.