Toggles and Switches
Toggles allow users to select between a small number of mutually exclusive options.
Examples
Condensed Toggle
This variation may be used when a condensed version is preferred. It is especially suitable to toggles appearing within filters and alongside charts and other data visualizations.
Icon Toggle
A icon toggle may be used when the meaning of the icon is clear to the user. It is often preferable in mobile contexts, to conserve space.
Switches
A switch offers a clear on or off state and is typically used for immediate actions rather than being submitted as part of a form. It’s important to clearly indicate the option controlled by the switch, and its current state, through either a text label or an icon.
Developer Notes
Use of the toggle switch requires a JavaScript helper. It can be instantiated using new Spark.ToggleSwitch(el)
. It provides mechanisms for getting and setting the value.
Order Matters
For all toggles, the <input>
element must be the first item inside of the toggle container. Otherwise the disabled
state will not work properly.
The following options may be passed when using new Spark.ToggleSwitch(el, {});
:
For all available methods and full API, refer to the component code on Bitbucket.
Text Toggle
Condensed Toggle
To display a condensed Toggle, apply both the spark-toggle
and spark-toggle--xs
classes.
Icon Toggle
Switches
Accessibility Notes
Switches
When using a Switch, ensure that you provide a label that indicates the purpose of the Switch to users. The label can be provided as a text element right above the Switch component. An example is shown below with the label styling.
Switch Label
On small screens such as mobile devices or in containers that are approximately the width of a small mobile device, it might be beneficial to place the label and the Switch side-by-side, with the Switch aligned to the right of the container/screen. This will however depend on the length of your label and how you plan to account for any wrapping text. The example below illustrates one possible way of accomplishing this. Note that the max-width of the container that holds the label and Switch is set to 320px.