Docs

Multi-Select Combo Box

How to add a combo box to your project for users to be able to make multiple selections.

Multi-Select Combo Box allows the user to choose one or more values from a filterable list of options presented in an overlay. The component supports the same features as the regular Combo Box, such as lazy loading or allowing custom typed values. This page explains how to add this component to your project and how to configure it.

Open in a
new tab
const [items, setItems] = useState<Country[]>([]);

useEffect(() => {
  getCountries().then((countries) => setItems(countries));
}, []);

return (
  <MultiSelectComboBox
    label="Countries"
    itemLabelPath="name"
    itemIdPath="id"
    items={items}
    style={{ width: '300px' }}
  />
);

The overlay opens when the user clicks the field using a pointing device. Using the Up and Downarrow keys or typing a character (that occurs in at least one of the options) when the field is focused also opens the popup.

Common Combo Box Features

Multi-Select Combo Box supports the following features from the regular Combo Box. All the linked examples and code snippets can be applied by replacing the Combo Box with a Multi-Select Combo Box.

Selection

The component allows selecting multiple values, each of which is displayed as a chip inside the component. If there isn’t enough space in the component to display chips for all selected values, then some values are collapsed into an overflow chip. The example below shows a Multi-Select Combo Box with multiple preselected values, some of which are collapsed into the overflow chip:

Open in a
new tab
const [items, setItems] = useState<Country[]>([]);
useEffect(() => {
  getCountries().then((countries) => setItems(countries));
}, []);

return (
  <MultiSelectComboBox
    label="Countries"
    itemLabelPath="name"
    itemIdPath="id"
    items={items}
    selectedItems={items.slice(0, 4)}
    style={{ width: '300px' }}
  />
);

When the overlay is closed, items can be removed one by one (starting with the most recently selected item) using the Backspace key. The first Backspace press moves focus to the last chip; the second press removes that chip, and the corresponding item, from the selection.

Selection Change

The following example demonstrates how to listen for selection changes:

Open in a
new tab

Use the selected-items-changed event to react to the user changing the selection.

Use addValueChangeListener() to be notified about the user changing the selection. Alternatively addSelectionChangeListener() can be used to get more detailed information about the selection change.

const [selectedCountries, setSelectedCountries] = useState<Country[]>([]);
const selectedCountriesText = selectedCountries.map((country) => country.name).join(', ');

return (
  <HorizontalLayout theme="spacing">
    <MultiSelectComboBox
      label="Countries"
      itemLabelPath="name"
      itemIdPath="id"
      items={items}
      selectedItems={selectedCountries}
      onSelectedItemsChanged={(event) => {
        setSelectedCountries(event.detail.value);
      }}
    />

    <TextArea label="Selected Countries" readonly value={selectedCountriesText} />
  </HorizontalLayout>
);

Read-Only

The component can be set to read-only, which prevents the user from modifying its value. A read-only Multi-Select Combo Box still allows opening the overlay, which then shows only the selected values, instead of all the options. This can be useful if selected values have been collapsed into the overflow chip.

Open in a
new tab
<MultiSelectComboBox
  label="Countries"
  itemLabelPath="name"
  itemIdPath="id"
  items={items}
  selectedItems={items.slice(0, 4)}
  readonly
  style={{ width: '300px' }}
/>

Internationalization (i18n)

Multi-Select Combo Box allows localizing the following messages. These texts are only used in screen reader announcements, and can’t be observed visually.

Message Default Description

cleared

"Selection cleared"

Announced by screen readers when the clear button is clicked

focused

" focused. Press Backspace to remove"

Announced by screen readers when a chip is focused

selected

" added to selection"

Announced by screen readers when an item is added to the selection.

deselected

" removed from selection"

Announced by screen readers when an item is removed from the selection.

total

"{count} items selected"

Announced by screen readers to inform about the total number of selected items. The string must contain a {count} placeholder, which is replaced with the actual count of selected items by the component.

The following example demonstrates how to localize the component’s messages into German:

Open in a
new tab
const i18n = {
  cleared: 'Alle Einträge entfernt',
  focused: ' ausgewählt. Drücke Rücktaste zum Entfernen',
  selected: ' hinzugefügt',
  deselected: ' entfernt',
  total: '{count} Einträge ausgewählt',
};

return (
  <MultiSelectComboBox
    label="Länder"
    itemLabelPath="name"
    itemIdPath="id"
    items={items}
    i18n={i18n}
    style={{ width: '300px' }}
  />
);

Best Practices

Multi-Select Combo Box supports lazy loading for large datasets. It reduces the initial load time, and consumes less bandwidth and resources.

For consistency, the default width of the Multi-Select Combo Box matches that of other input fields. You should increase the width of the component when using items with long labels, or if you expect users to select several items, to avoid collapsing selected items into the overflow chip.

Example of increasing component width
<MultiSelectComboBox style={{ width: '300px' }} />
Component Usage recommendations

Combo Box

Same feature set, but for selecting a single value.

List Box

Scrollable inline list of options. Supports single and multi-select.

Checkbox Group

Serves the same purpose in a more user-friendly format, but takes up more vertical space.