Skip to main content
Login

Sign in to access your account

Multiselect - National Design System

A form field whose menu of checkboxes lets the user pick several options, shown in the field as removable chips

Overview

A multiselect is a form field with a Dropmenu at its start. The menu holds a group of checkboxes, and each checked option shows in the field as a chip. The checkboxes are the values: the form submits the checked ones, with no hidden inputs.

Pick another component when:

  • the user picks one option: a custom select in Forms
  • the user types free values as chips: Tag Input
  • a few options fit on the page with no menu: a checkbox group in Checkbox

Markup

Options
Structure
Menu button
Menu options
Chip color
State
Validation
Preview
Select options
<div class="nds-form-container nds-multiselect" data-multiselect-name="interests"> <div class="nds-form-header"> <label><span class="nds-label">Interests</span></label> </div> <div class="nds-form-control"> <div class="nds-form-action nds-prefix nds-dropmenu" data-multiselect-dropmenu> <button class="nds-btn nds-subtle nds-menu-btn nds-dropmenu-trigger" type="button"> <i class="nds-icon nds-hgi-menu-01" aria-hidden="true"></i> <span class="nds-label">Select</span> </button> <div class="nds-dropmenu-menu" hidden> <div class="nds-dropmenu-scroll"> <fieldset class="nds-form-group nds-checkbox-group nds-dropmenu-group" data-no-auto-close> <legend class="nds-label">Technology</legend> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="ms-ai"><span class="nds-label">AI &amp; ML</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="ms-ai" class="nds-checkbox-input" name="interests[]" value="ai" data-label="AI &amp; ML" checked> </div> </div> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="ms-cloud"><span class="nds-label">Cloud</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="ms-cloud" class="nds-checkbox-input" name="interests[]" value="cloud" data-label="Cloud"> </div> </div> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="ms-security"><span class="nds-label">Cybersecurity</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="ms-security" class="nds-checkbox-input" name="interests[]" value="security" data-label="Cybersecurity"> </div> </div> </fieldset> <hr class="nds-divider"> <fieldset class="nds-form-group nds-checkbox-group nds-dropmenu-group" data-no-auto-close> <legend class="nds-label">Design</legend> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="ms-ux"><span class="nds-label">UX Research</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="ms-ux" class="nds-checkbox-input" name="interests[]" value="ux" data-label="UX Research" checked> </div> </div> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="ms-brand"><span class="nds-label">Brand Identity</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="ms-brand" class="nds-checkbox-input" name="interests[]" value="brand" data-label="Brand Identity"> </div> </div> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="ms-motion"><span class="nds-label">Motion</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="ms-motion" class="nds-checkbox-input" name="interests[]" value="motion" data-label="Motion"> </div> </div> </fieldset> </div> </div> </div> <div class="nds-chips nds-multiselect-chips" data-multiselect-chips></div> <span class="nds-multiselect-placeholder">Select options</span> </div> </div>

Behavior

Data-driven Options

The script builds the option rows from the JSON in data-multiselect-options on .nds-multiselect. It puts them in the empty .nds-dropmenu-scroll. The JSON is an array of values, where each value is also its label, or an object of value: label pairs. An object of objects, {"Technology": {"ai": "AI & ML"}}, makes one fieldset per key, with the key as its legend. data-multiselect-selected holds an array of the values to check at load. The built rows replace any rows in the menu. renderOptions() does the same from code.

Apply Button

With no Apply button, each check commits at once: the chips change and nds:multiselect:change fires. A button with data-multiselect-action="apply" in the menu makes checks wait. The user checks options in the menu, and Apply commits them. Closing the menu without Apply undoes them. Removing a chip undoes them too. A form submit while the menu is open checks and sends the committed options, not the waiting ones.

Reset Button

A button with data-multiselect-action="reset" in the menu unchecks every option. With no Apply button, the reset commits at once. With an Apply button, it unchecks the options in the menu only, and Apply commits the empty set. data-no-auto-close keeps the menu open after the click.

data-search on the [data-multiselect-dropmenu] element adds a search box at the top of the menu. The box hides each row with data-search-item whose text does not match. data-search="20" adds the box only when the menu holds 20 rows or more, counted when the menu opens. For Data-driven, keep the empty .nds-dropmenu-scroll in the menu.

Validation

data-required, data-min-checked and data-max-checked on .nds-multiselect count the checked options when the form submits. data-required alone means at least one. The error shows on the field. After an error shows, the field checks again on each change and clears the error when the count is right.

Disabled and Read-only

data-state~="disabled" on .nds-multiselect disables the menu button and every chip. With data-state~="readonly", the menu button still works, so the user can open the menu and see all options. The options, the chips and Reset do not change anything. Code can still change the value with setValues(), removeValue(), clear() and renderOptions().

Built-in Features

  • Auto-initialization

    Every .nds-multiselect on the page starts on load, with its dropmenu. The chips for checked options show before the page appears.

  • Removable Chips

    A click on a chip unchecks its option and commits at once, with or without an Apply button. Focus moves to the next chip, or to the menu button after the last one.

  • Native Form Submission

    The form submits each checked checkbox by its name and value. A checkbox with no name gets name="{data-multiselect-name}[]", so the server reads an array.

  • Saved Values

    To show a saved value, write checked on its options. The field builds their chips when it starts, with no script on the page.

  • Whole-Field Click

    A click anywhere on the field, except on a chip, opens the menu. The menu lines up with the start edge of the field.

  • Keyboard Navigation

    In the open menu, the arrow keys move through the options and the menu buttons, and Space checks an option. Escape closes the menu and moves focus back to the menu button.

  • Screen Reader Support

    The menu button's name lists the chosen options, such as "Select: AI & ML, Cloud". A screen reader reads each change, such as "Added Cloud", in English or Arabic.

  • Menu Placement

    In a drawer, a modal or another scroll area that would cut it off, the menu moves to <body> while it is open.

Best Practices

  • Group a long list in fieldsets with a legend, and put an <hr class="nds-divider"> between the fieldsets. A screen reader reads the legend with each option.
  • Add the Apply button when the user checks many options before the result matters, such as a filter. Leave it off a short list.
  • Give each checkbox a data-label. The chip shows it, and the label can then hold more text than the chip needs.
  • Give an icon-only menu button an aria-label, such as “Select”. The script adds the chosen options to it.
  • Keep the placeholder to two to four words. It shows only while no option is checked.
  • Add data-search for a list longer than about 15 options.
  • Say a count rule in the label, such as “Interests (2 to 4)”, not in the placeholder.
  • For the label, info text, feedback and the required mark, see Forms. They work the same on every field.
  • The field colors come from the form tokens: see Forms, Tokens.

API

Other Classes

Class Element Effect
.nds-multiselect-menu .nds-dropmenu-menu The script adds it when the field starts. Style the menu through this class: it stays on the menu when the menu moves to <body>

Data Attributes

Attribute Element Effect
data-multiselect-name .nds-multiselect The field name. The script gives it, with [] after it, to each checkbox that has no name. It is also name in the change event
data-multiselect-options .nds-multiselect JSON options that the script builds into the menu. See Data-driven Options
data-multiselect-selected .nds-multiselect A JSON array of the values to check at load, spelled as in the options. Used only with data-multiselect-options
data-chip-class .nds-multiselect The classes on each chip. The default is nds-primary nds-sm. See Chips
data-required, data-min-checked, data-max-checked .nds-multiselect The count rules. See Validation
data-state~="filled" .nds-multiselect The script sets it when an option is checked, and removes it when none is. It hides the placeholder. destroy() removes it
data-state~="focus" .nds-multiselect The script sets it while the menu button has focus or the menu is open, and removes it when both end
data-state~="disabled", data-state~="readonly" .nds-multiselect Set it yourself. See Disabled and Read-only
data-multiselect-dropmenu the .nds-dropmenu element Marks the dropmenu that holds the options. Without it, the script uses .nds-form-action.nds-prefix.nds-dropmenu
data-anchor the .nds-dropmenu element Where the menu lines up. The script sets start when the element has no data-anchor. Write center or end to change it
data-search the .nds-dropmenu element Adds the search box. See Search
data-multiselect-chips .nds-multiselect-chips Marks the element that holds the chips. The script fills it. Without it, the script uses .nds-multiselect-chips
data-no-auto-close each <fieldset>, and the Reset button A click on it leaves the menu open
data-multiselect-action a button in .nds-dropmenu-footer reset makes a Reset button, and apply an Apply button. See Reset Button and Apply Button
data-label each checkbox The chip text. Without it, the chip shows the option’s .nds-label text
data-search-item each .nds-checkbox The search box filters this row. Data-driven adds it when the dropmenu has data-search

Tokens

It reads these shared tokens. A change to one also changes other components: see Tokens.

Source: the var() reads in _sass/components/_multiselect.scss.

TokenPreviewValue
--form-field-text-placeholder
Read by color

var(--text-secondary-paragraph)
Dark mode var(--colors-neutral-400)

JavaScript

Method Effect
NDS.Multiselect.init() Starts every .nds-multiselect that has not started. The loader calls it on load. Call it again after you add a field to the page
NDS.Multiselect.create(el) Starts one field, and returns its instance. On a field that has started, it returns the same instance. It returns null when the field lacks a required part
NDS.Multiselect.destroy(el) Removes the listeners, the chips and the dropmenu it started, and closes an open menu. The checked options stay. A dropmenu that the page started before create() stays. Call it before you remove the field from the page
NDS.Multiselect.validate(el, options) Checks the field and returns { valid, message, checked, min, max }. Pass { showMessage: false } to check without a message
el.ndsMultiselect The instance of a field that has started
NDS.Multiselect.getValues(el) Returns the values of the checked options, in menu order, or [] when the field is not found. el is the .nds-multiselect, its id or a selector
NDS.Multiselect.setValues(el, values) Checks exactly the options in the array values, commits, and returns true. It returns false, and changes nothing, when a value has no option
NDS.Multiselect.clear(el) Unchecks every option and commits. Returns true, or false when the field is not found
instance.getValues() Returns the values of the checked options, in menu order
instance.setValues(values) The same as NDS.Multiselect.setValues, on a field that has started. The change event fires once
instance.apply() Applies the checked options: the chips change and the change event fires. The Apply button calls it
instance.clear() Unchecks every option and commits. With an Apply button and the menu open, it unchecks them in the menu only. Returns true
instance.removeValue(value) Unchecks one option and commits
instance.renderOptions(options, selected) Replaces the options. It takes the shapes that data-multiselect-options takes, and an array of values to check. It fires no change event
Event Fired on Detail
nds:multiselect:change .nds-multiselect, and it bubbles { name, values, labels }, after each commit. name is data-multiselect-name. values and labels are the checked options, in the same order
var field = document.querySelector('.nds-multiselect[data-multiselect-name="cities"]'); // Show the count next to the field field.addEventListener('nds:multiselect:change', function (e) { document.querySelector('#city-count').textContent = e.detail.values.length + ' selected'; }); // Load the options from the server, and keep the saved ones checked NDS.request('/api/cities').then(function (res) { field.ndsMultiselect.renderOptions(res.data, ['riyadh']); });

The full API is in the banner of _js/nds-multiselect.js.

Last Modified Date: 05/11/2026 - 12:02 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks