Preview brand Custom

Multi-choice drop-down

A drop-down for filters where more than one choice can be on: a tickbox by each option, and the field says what's chosen.

Beta

Where
Where
Show code
astro
<MultiSelect id="where" label="Where" none="Anywhere"
  options={[{ value: 'bvi', label: 'British Virgin Islands' }, …]} />

<!-- By script -->
import { createMultiSelect } from '@somnia/core/lib/multi-select.js';
const where = createMultiSelect({ id: 'where', label: 'Where', none: 'Anywhere', options });
form.append(where.root);
where.root.addEventListener('change', () => where.values); // ['bvi', 'exumas']

When to use it

  • A filter where several choices can be on together: topics, statuses, places.
  • The choices are few enough to read down in one go.

Use something else when:

  • Only one choice can be on: an ordinary drop-down (select), which a phone shows in its own picker.
  • There are two or three choices and room to show them: tickboxes on the page, with nothing to open.
  • It is one thing on or off: a Switch.

How it works

  • The field reads the none wording (“All topics”, “Anywhere”) when nothing is ticked, the option when one is, and “3 chosen” when more are (change it with chosen, a function of the number).
  • The list is a group of real tickboxes, named by the field's label, with Clear under them. It opens downwards, or upwards when there's no room below.
  • A change event on the element carries the ticked values (event.detail.values). By script, values reads and sets them and setOptions(options) replaces the list, keeping what's still there ticked.

Do and don't

Do

  • Word "nothing chosen" as what it means: "All topics", "Anywhere"
  • Label it with what is being chosen
  • Show what the page did with the choice straight away

Don't

  • Use it for one choice
  • Hide a long list of dozens behind it with no way to search
  • Use "None" for nothing chosen when it means everything

Accessibility

What it does for you

  • A button whose name is the label and what is chosen ("Topic, 2 chosen"), saying whether its list is open.
  • The list is a group of real tickboxes, named by the label, so keyboards, screen readers and forms treat them as any tickbox.
  • Each option’s whole row is the target, at least 40px high.
  • It closes on Escape (back to the button), a click outside, or Tab past its end. It opens upwards when there is no room below.
  • Clear, under the options, unticks them all.

What you need to do

  • A label that says what is being chosen.
  • Wording for nothing chosen that says what that means ("All topics", not "None").
  • Use it only where several can be on together. For one choice use an ordinary drop-down, which a phone shows in its own picker.

Keyboard

KeyWhat it does
TabTo the button; with the list open, into it and through the tickboxes, and past its end, which closes it.
Enter or SpaceOn the button: opens or closes the list.
Up and Down arrowsMove between the tickboxes.
SpaceTicks or unticks an option.
EscapeCloses the list and goes back to the button.

What a screen reader is told

  • The button: the label and what is chosen, and expanded or collapsed.
  • The list: a group named by the label. Each option: a checkbox, its name, ticked or not.

This is what the browser reports to assistive technology. What each screen reader then says varies, and has not been listened to yet.

WCAG 2.2

CriterionLevelHow this meets it
1.3.1 Info and RelationshipsAThe options are a named group of checkboxes.
2.1.1 KeyboardAOpen, move, tick, clear and close from the keyboard.
2.1.2 No Keyboard TrapAEscape or Tab past the end always leaves the list.
2.4.7 Focus VisibleAAThe button and each option show the focus ring.
2.5.8 Target Size (Minimum)AARows are at least 40px high.
3.2.2 On InputATicking changes the choice only; what the page does with it is the page’s to make plain.
4.1.2 Name, Role, ValueAThe button reports expanded or collapsed and names what is chosen.

The criteria this component has a part in. A page that uses it still has to meet the rest.

Checked

CheckHowResult
Automated (axe-core)WCAG 2.0, 2.1 and 2.2 rules at A and AA, the page in light and in darkPassed
Nothing found, light or dark
Narrow screenNo sideways scrolling at 320px wide (WCAG 1.4.10)Passed
No sideways scrolling
Keyboard and what the browser reportsReal key presses on the live example, and the role, name and state given to assistive technologyPassed
7 of 7 checks pass
On paperSomnia’s print check: no overlaps, stranded headings or controls on the pagePassed
No faults on 5 sheets
Screen readerListened to by a person, in VoiceOver and NVDANot yet
Not yet checked by a person

The 7 checks made with the keyboard, on the example at the top of this page:

  • Passed Tab reaches the button
  • Passed The browser reports the button with its label and what is chosen, collapsed
  • Passed Enter opens the list: a group named by the label, with focus on the first tickbox
  • Passed Down arrow moves to the next tickbox, and Space ticks it
  • Passed With two ticked, the button says "2 chosen"
  • Passed Escape closes the list and goes back to the button
  • Passed Each option’s row is at least 40px high

Run by script on against Somnia DS 1.89.0, in Chromium with axe-core 4.14.0. How these checks work, and every component's results.

Not yet checked

  • How it sounds in a screen reader (VoiceOver, NVDA, TalkBack) has not been checked by a person. The roles, names and states the browser reports are checked by script; what is actually spoken is not.
  • Windows high contrast (forced colours) has not been looked at by a person.

Evidence

Where it's used

WhereFor
Somnia CMSThe Topic and Status filters above a list of entries, and the filters in the media library.

What we saw, and what changed

WhenWhat we sawWhat changed
The editor’s lists needed a filter where several topics could be on at once; a plain drop-down takes one.Built as a new component, with real tickboxes inside (1.42.0).
In Safari, ticking an option closed the list before the tick landed: Safari doesn’t focus a clicked tickbox.The list closes only when focus moves to something outside it, or on a click outside (1.43.1).
It stood a little taller than a plain drop-down beside it.The same height (1.75.0); its chevron and phone-size label had been matched to a plain drop-down’s four days before (1.64.0).
This page said each option’s row was at least 40px high; measured, it was 39px.Rows have a least height of 40px (1.81.0).

From building and using it on real sites, each entry taken from the changelog or the build's own notes. This is observation by the studio and its clients, not research sessions with users.

What it rests on

What we don't know yet

  • A long list (dozens of options) has no search inside it.
  • Used only inside Somnia CMS so far; no public page has one.