Multi-Select
A Multi-Select input is a form control for selecting multiple items from a list of options. There are two variations in Spark: a custom component and a native control.
- Native Multi-Select Example
- Examples
- Examples
- Developer Notes
- Right-to-Left Support
Native Multi-Select Example
When to Use
- To allow the user to select two or more options from a list.
- The native version may be preferred for applications primarily accessed on a mobile device.
When Not to Use
- If only one option may be selected (see Radio Buttons or Select).
- The native version is not recommended when consistency across browsers/devices is desired, custom formatting is needed, and/or awareness of browser events is needed for validation or other purposes.
Examples
- Native Example (shown above)
- Custom Example
- Native Error State
- Custom Error State
Examples
Custom Multi-Select
When to Use:
- The custom version is recommended when display options not available in the native control are desired. Examples include: displaying icons next to options and formatting airport names and city codes to be easily scanned.
- When consistency across browsers/devices is required.
- When awareness of browser events is required for validation or other purposes.
Native Error State
Custom Error State
Developer Notes
Using the JavaScript helper with the Multi-Select is not required, but it does provide some enhanced functionality. It implements the Messaging and Validation mixins, and provides mechanisms for getting and setting the value.
The following options may be passed when using new Spark.MultiSelect(el, {});
:
For all available methods and full API, refer to the component code on Bitbucket.
Native Multi-Select
This component is built on top of the native select[multiple]
component, allowing browsers to present a system-specific implementation. This is most important on mobile devices where a native selector could be preferred. However, there are limitations; most styles will be overridden by the system implementation, and some browser events are not triggered while the user is interacting with the system implementation. The restrictions and behavior of this element varies with device and browser. In order to see the exact behavior for a given combination, please try these components on the devices and browser combinations you would like to support.
States
There are 5 distinct states supported:
- Native Default State
- Native Disabled State
- Native Data Success State
- Native Data Warning State
- Native Data Error State
You may also use these states without a title.
You can set the number of options to show by default by giving the .spark-multi-select__input
element the size
property with an integer value. Setting no size
property will cause the element to display all options without scrolling.
Native Default State
Native Default State (No Title)
Native Disabled State
Native Data Success State
Native Data Warning State
Native Data Error State
Custom Multi-Select
Because of the limited amount of styling that can be applied to a native multi-select, Spark also includes a custom multi-select implementation. It is easier to use for most users and is more in line with Spark’s visual styling, but it may not be ideal for some mobile instances.
States
There are 5 distinct states supported:
You may also use these states without a title.
The component starts in the default state, and you can set optional states by giving the .spark-multi-select
element the properties disabled
, data-success
, data-warning
, and/or data-error
. You may remove the title by removing the .spark-multi-select__label
element.
You can set the number of options to show by default, by giving the .spark-multi-select
element the size
property with an integer value. This will show n
options, with the last element being half hidden to help show the user there are more options below. Setting no size
property will cause the element to grow to display all options without scrolling.
Default State
Default State (No Title)
Disabled State
You may selectively disable individual options by giving the option’s respective .spark-checkbox__input
element the disabled
property. (Learn more about Checkboxes)
When you place your Multiple Select element in the disabled
state, the .spark-select__message
will be hidden.