For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /dolan/multi-select.md.

Multi Select

A field that opens a sheet of checkboxes and shows every option the user picks as a chip.

Installation

npx @blotch/dolan add multi-select
import {
  UiMultiSelect,
  UiMultiSelectItem,
} from '../components/ui/multi-select';
Tip

This also adds Select, whose sheet and search it shares, and the Checkbox, Badge and Button it draws with.

Usage

src/app/app.ts
import { Component, signal } from '@angular/core';
import {
  UiMultiSelect,
  UiMultiSelectItem,
} from '../components/ui/multi-select';

@Component({
  selector: 'app-root',
  imports: [UiMultiSelect, UiMultiSelectItem],
  template: `
    <ui-multi-select
      label="Topics"
      placeholder="Choose topics"
      [(value)]="topics"
    >
      <ui-multi-select-item value="news" label="News" />
      <ui-multi-select-item value="sport" label="Sport" />
      <ui-multi-select-item value="science" label="Science" />
    </ui-multi-select>
  `,
})
export class App {
  protected readonly topics = signal<readonly string[]>([]);
}
  • Tapping the field opens the sheet. Each item has a checkbox.
  • Tapping an item toggles it. The sheet stays open.
  • Done, the dimmed backdrop, or dragging the handle down closes the sheet.
  • value lists the chosen values in the order they were chosen.
  • The field shows the chosen items' labels as chips, in that order. It grows onto more lines as they need. With none chosen, it shows placeholder.

Add searchable for a long list. It works as Select's search does:

<ui-multi-select label="Topics" searchable [(value)]="topics">
  @for (topic of allTopics; track topic) {
    <ui-multi-select-item [value]="topic" [label]="topic" />
  }
</ui-multi-select>
  • The sheet opens at full height, with a search field under its header.
  • Typing hides the items whose label doesn't contain the text. Case doesn't matter.
  • emptyText shows when nothing matches.
  • Set [filter]="false" to show results of your own for [(query)].

Icons

Content in an item, such as an Icon, goes between its checkbox and its label:

<ui-multi-select-item value="rain" label="Rain">
  <ui-icon name="cloud-rain" size="sm" />
</ui-multi-select-item>

Disabled

<ui-multi-select label="Features" [value]="['sync']" disabled>
  <ui-multi-select-item value="sync" label="Sync" />
</ui-multi-select>

A disabled field dims and doesn't open.

Open from code

UiMultiSelect has public open(), close() and toggle() methods. Get it with viewChild(UiMultiSelect) and call them from a handler. open() and toggle() do nothing while disabled.

Accessibility

  • The field is one button to VoiceOver and TalkBack, named by label (or accessibility-label). Its value is the chosen labels, or the placeholder: VoiceOver says "Topics, News, Sport, button".
  • The sheet's title is a heading, and Done is a button.
  • Each item is a button named by its label, and selected while it's chosen.

So a spec finds them by role:

fireEvent.tap(screen.getByRole('button', { name: 'Topics' }));
fireEvent.tap(await screen.findByRole('button', { name: 'News' }));
expect(
  screen.getByRole('button', { name: 'News', selected: true }),
).toBeTruthy();

API

UiMultiSelect

InputTypeDefaultDescription
valuereadonly string[][]The chosen values, in the order they were chosen. Supports [(value)].
labelstring''Shown above the field and as the sheet's title. Names it for screen readers.
placeholderstring'Select...'Shown in the field while nothing is chosen.
accessibility-labelstring''The field's name for screen readers, and the sheet's title, with no label.
disabledbooleanfalseDims the field and stops it from opening.
classstring''Extra Tailwind classes for the column that holds the label and the field.
searchablebooleanfalseShows a search field in the sheet, which opens at full height.
querystring''The search text. Supports [(query)]. Cleared when the sheet closes.
filterbooleantrueHides the items whose label doesn't contain query, ignoring case.
searchPlaceholderstring'Search'Shown in the search field while it's empty.
emptyTextstring'No results'Shown in a searchable sheet while no item is.
doneLabelstring'Done'The label of the button that closes the sheet.
OutputTypeDescription
changedreadonly string[]Emits the new value every time an item is toggled.
valueChangereadonly string[]Emits the new value, for [(value)].
queryChangestringEmits the search text, for [(query)].

UiMultiSelectItem

InputTypeDefaultDescription
valuestringRequiredThe value this item adds to the selection.
labelstringRequiredThe text shown in the list and in its chip.
classstring''Extra Tailwind classes for the item's row.

No outputs. Content inside the item, such as an icon, goes between its checkbox and its label.

  • Select: pick one option
  • Checkbox: a single on/off box
  • Toggle: a group of buttons that stay pressed, for a few options on screen