Skip to content

Machine-translated – improvements welcome. Suggest an improvement

Multiple selection

Mehrfachauswahl (#1211; previously in web/src/ablage/) chooses one or several entries: a search field with a magnifier and suggestions on top, the chosen entries below, each with a small ✕ button. That is how you choose folders in a link field or the folder types of the advanced search.

What it is for

For choosing folders, people, organisations or other entries from a longer list – like a link field: search while typing, choose from suggestions, create one right away if needed. A few fixed choices are a select in a Field or ticks in a FeldGruppe; searching in a list is the Search.

Matching patterns in the pattern catalogue: A1 · Choosing folders, people, organisations = like a reference field, A2 · Multi-select, C18 · Position of menus: below if there is room, otherwise above, never over the assistant, C6 · “+ …” only where you create something.

How to use it

With How it works
Mouse Type into the search field and click one of the suggestions below. “+ Create …” is the last entry of the list. The ✕ on a chosen entry removes it.
Keyboard Arrow keys move through suggestions and create entries (focus stays in the search field, aria-activedescendant), Enter takes the highlighted one – without a highlight the first suggestion. Esc with the list open only closes the list (#1311): focus stays in the field, the input stays, and the key press goes no further – it discards no changes of the save bar and closes no window. Only another Esc with the list closed acts as everywhere else (save bar: discard, window: close). After the ✕ the focus is in the search field.
Touch Search field, suggestions, create entries and ✕ are at least 44 px high. The suggestions stay at the field and scroll with it (no sheet from below, the search field stays visible).

What it means

  • Chosen entries stand below the field, each with a small ✕ button – so fields stay at one height (pattern catalogue A2).
  • Creating is in the list, not a green button below the field: green is reserved for creating on the page (principle 2).
  • ✕ is a small symbol-only button (kind secondary), not red: the field only changes on saving (principle 5). Its screen reader name is entfernenText, e.g. “Remove holder”. Afterwards focus is in the search field.
  • No results: a quiet sentence says what was not found (“Contract “xyz” not found”).

Position

Position (#1670, mehrfachauswahl/lage.ts): the suggestions open by the rule of the menus (aufklapplage): downwards if there is room, otherwise upwards – e.g. for a reference field at the bottom of a folder. They are at most 280 px high and stay inside the visible part of the column; the rest scrolls in the list, not on the page. They are placed again on scrolling and resizing. Unlike the menu they stay at the field (position: absolute) and scroll with it, on the phone too (no sheet from below, the search field stays visible).

States

State How it comes about How it looks
empty nothing chosen search field with magnifier and placeholder
open with results offen, vorschlaege suggestions below or above the field, the highlighted one marked, “+ Create …” at the end
loading vorschlaege={null} suggestion list waits
no results empty vorschlaege leerText, quiet
set one entry in gewaehlt entry with ✕ below the field
multiple several entries entries one below the other, each with ✕

“Multiple selection” section of the pattern page: empty, open with results, no results, set, multiple

“Multiple selection” section, dark

Accessibility

The search field is a combobox (aria-expanded, aria-controls, aria-autocomplete="list") and points to the highlighted suggestion with aria-activedescendant – the focus stays in the field. The suggestions are a listbox with options (aria-selected), groups are groups with a name. The list of chosen entries and the suggestions have name as their name. Every ✕ has entfernenText as its name. Esc first closes the list and doesn't go on to the save bar or window.

Code

Prop Purpose
name name of the list of chosen entries and of the suggestions (for screen readers)
platzhalter, eingabeLabel, id placeholder and label of the search field (or id for a <label htmlFor>)
eingabe, setEingabe, offen, setOffen text and state of the suggestion list – held by the caller, because it loads suggestions depending on them
vorschlaege { id, text, gruppe? }[]; null means: still loading
leerText, fuss quiet sentence without suggestions (e.g. “Contract “xyz” not found”); something below the suggestions (e.g. “… in total”)
anlegen, legeAn entries for creating (#1288, { id, text }[]), always last in the list – also with results; legeAn gets their id
waehle, gewaehlt, entferne take a choice; the chosen entries ({ id, inhalt, zusatz?, aktionen?, entfernenText }); remove an entry
ohneSuche, darunter, schliessen without a search field (single choice with a value); something below the chosen entries; when the suggestions close
imFluss suggestions always below, without own placement – only for the pattern page and pictures

Files and tests

  • Building block: web/src/bausteine/mehrfachauswahl/Mehrfachauswahl.tsx, look: Mehrfachauswahl.module.css, position: lage.ts
  • Pattern page: web/src/bausteine/mehrfachauswahl/muster.tsx – section Multiple selection: empty, open with results, no results, set and multiple
  • Test: web/test/baustein-mehrfachauswahl-lage.test.ts