# Multi select

A dropdown for picking any number of values from a list, shown in the field as text or as removable chips. The value is an array in selection order.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-multi-select`, `ng-template[vigSelectOption]`
- Source: [libs/ui/src/lib/molecules/multi-select/multi-select.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/molecules/multi-select/multi-select.ts)

```typescript title="Import"
import { MultiSelect } from '@vigdx/ui/multi-select';
import { SelectOptionTemplate } from '@vigdx/ui/select';
```

## Basic

Pass `options` as `SelectOption` objects and bind `[(value)]` to an array; empty is `[]`. The list stays open while you pick. Past `maxSelectedLabels` (3 by default) the field shows a count such as `3 selected` instead of the labels.

```typescript title="multi-select-basic.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { MultiSelect } from '@vigdx/ui/multi-select';

import { SKILLS } from './options';

@Component({
  selector: 'app-multi-select-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [MultiSelect],
  template: `
    <div class="grid gap-4 sm:grid-cols-2">
      <vig-multi-select
        label="Skills"
        placeholder="Pick your skills"
        [options]="skills"
        [(value)]="picked"
      />
      <vig-multi-select
        label="Skills (summary)"
        [options]="skills"
        [maxSelectedLabels]="2"
        [value]="['angular', 'typescript', 'css']"
      />
    </div>
    <p class="text-sm text-muted-foreground">Value: {{ picked().join(', ') || '[]' }}</p>
  `,
})
export class MultiSelectBasicDemo {
  protected readonly skills = SKILLS;
  protected readonly picked = signal<string[]>(['angular', 'typescript']);
}
```

```typescript title="options.ts"
import type { SelectOption } from '@vigdx/ui/select';

export const SKILLS: SelectOption[] = [
  { value: 'angular', label: 'Angular' },
  { value: 'typescript', label: 'TypeScript' },
  { value: 'rxjs', label: 'RxJS' },
  { value: 'css', label: 'CSS' },
  { value: 'a11y', label: 'Accessibility' },
  { value: 'node', label: 'Node.js' },
  { value: 'sql', label: 'SQL' },
  { value: 'go', label: 'Go', disabled: true },
];

export const COUNTRIES: SelectOption[] = [
  { value: 'de', label: 'Germany' },
  { value: 'fr', label: 'France' },
  { value: 'it', label: 'Italy' },
  { value: 'nl', label: 'Netherlands' },
  { value: 'pl', label: 'Poland' },
  { value: 'es', label: 'Spain' },
  { value: 'se', label: 'Sweden' },
  { value: 'tr', label: 'Türkiye' },
];
```

## Chips

`display="chip"` shows each selection as a chip with its own remove button. Long chips truncate instead of widening the field.

```typescript title="multi-select-chips.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { MultiSelect } from '@vigdx/ui/multi-select';

import { SKILLS } from './options';

@Component({
  selector: 'app-multi-select-chips',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [MultiSelect],
  template: `
    <div class="max-w-md">
      <vig-multi-select
        label="Skills"
        display="chip"
        [options]="skills"
        [maxSelectedLabels]="5"
        [(value)]="picked"
      />
    </div>
  `,
})
export class MultiSelectChipsDemo {
  protected readonly skills = SKILLS;
  protected readonly picked = signal<string[]>(['angular', 'a11y', 'css']);
}
```

```typescript title="options.ts"
import type { SelectOption } from '@vigdx/ui/select';

export const SKILLS: SelectOption[] = [
  { value: 'angular', label: 'Angular' },
  { value: 'typescript', label: 'TypeScript' },
  { value: 'rxjs', label: 'RxJS' },
  { value: 'css', label: 'CSS' },
  { value: 'a11y', label: 'Accessibility' },
  { value: 'node', label: 'Node.js' },
  { value: 'sql', label: 'SQL' },
  { value: 'go', label: 'Go', disabled: true },
];

export const COUNTRIES: SelectOption[] = [
  { value: 'de', label: 'Germany' },
  { value: 'fr', label: 'France' },
  { value: 'it', label: 'Italy' },
  { value: 'nl', label: 'Netherlands' },
  { value: 'pl', label: 'Poland' },
  { value: 'es', label: 'Spain' },
  { value: 'se', label: 'Sweden' },
  { value: 'tr', label: 'Türkiye' },
];
```

## Filter, select all and clear

`filter` adds a search box, `showSelectAll` a row that selects or clears every visible option (only the filtered ones while a filter is typed), and `clearable` a button that empties the value.

```typescript title="multi-select-filter.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { MultiSelect } from '@vigdx/ui/multi-select';

import { COUNTRIES } from './options';

@Component({
  selector: 'app-multi-select-filter',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [MultiSelect],
  template: `
    <div class="max-w-sm">
      <vig-multi-select
        label="Markets"
        placeholder="All markets"
        [options]="countries"
        [filter]="true"
        [showSelectAll]="true"
        [clearable]="true"
        [value]="['de', 'fr']"
      />
    </div>
  `,
})
export class MultiSelectFilterDemo {
  protected readonly countries = COUNTRIES;
}
```

```typescript title="options.ts"
import type { SelectOption } from '@vigdx/ui/select';

export const SKILLS: SelectOption[] = [
  { value: 'angular', label: 'Angular' },
  { value: 'typescript', label: 'TypeScript' },
  { value: 'rxjs', label: 'RxJS' },
  { value: 'css', label: 'CSS' },
  { value: 'a11y', label: 'Accessibility' },
  { value: 'node', label: 'Node.js' },
  { value: 'sql', label: 'SQL' },
  { value: 'go', label: 'Go', disabled: true },
];

export const COUNTRIES: SelectOption[] = [
  { value: 'de', label: 'Germany' },
  { value: 'fr', label: 'France' },
  { value: 'it', label: 'Italy' },
  { value: 'nl', label: 'Netherlands' },
  { value: 'pl', label: 'Poland' },
  { value: 'es', label: 'Spain' },
  { value: 'se', label: 'Sweden' },
  { value: 'tr', label: 'Türkiye' },
];
```

## Translated labels

Every text the field adds can be set per instance: `selectedItemsLabel` (`{0}` is the count), `selectAllLabel`, `filterPlaceholder`, `filterAriaLabel`, `emptyMessage`, `clearAriaLabel` and `removeAriaLabel` (the option label is appended; `chipRemoveAriaLabel` is its deprecated name).

```typescript title="multi-select-labels.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { MultiSelect } from '@vigdx/ui/multi-select';

import { COUNTRIES } from './options';

@Component({
  selector: 'app-multi-select-labels',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [MultiSelect],
  template: `
    <div class="grid gap-4 sm:grid-cols-2">
      <vig-multi-select
        label="Pazarlar"
        placeholder="Tüm pazarlar"
        selectedItemsLabel="{0} ülke seçildi"
        selectAllLabel="Tümünü seç"
        filterPlaceholder="Ülke ara…"
        filterAriaLabel="Ülkeleri filtrele"
        emptyMessage="Sonuç bulunamadı"
        clearAriaLabel="Seçimi temizle"
        [options]="countries"
        [maxSelectedLabels]="2"
        [filter]="true"
        [showSelectAll]="true"
        [clearable]="true"
        [value]="['de', 'fr', 'tr']"
      />
      <vig-multi-select
        label="Pazarlar"
        display="chip"
        removeAriaLabel="Kaldır"
        [options]="countries"
        [value]="['it', 'tr']"
      />
    </div>
  `,
})
export class MultiSelectLabelsDemo {
  protected readonly countries = COUNTRIES;
}
```

```typescript title="options.ts"
import type { SelectOption } from '@vigdx/ui/select';

export const SKILLS: SelectOption[] = [
  { value: 'angular', label: 'Angular' },
  { value: 'typescript', label: 'TypeScript' },
  { value: 'rxjs', label: 'RxJS' },
  { value: 'css', label: 'CSS' },
  { value: 'a11y', label: 'Accessibility' },
  { value: 'node', label: 'Node.js' },
  { value: 'sql', label: 'SQL' },
  { value: 'go', label: 'Go', disabled: true },
];

export const COUNTRIES: SelectOption[] = [
  { value: 'de', label: 'Germany' },
  { value: 'fr', label: 'France' },
  { value: 'it', label: 'Italy' },
  { value: 'nl', label: 'Netherlands' },
  { value: 'pl', label: 'Poland' },
  { value: 'es', label: 'Spain' },
  { value: 'se', label: 'Sweden' },
  { value: 'tr', label: 'Türkiye' },
];
```

## Label, hint, error, states and sizes

`labelPosition="top"` puts the label above the field and `hideLabel` hides it for toolbars. Errors show once the field is `touched` and `invalid`. `readonly` keeps the field focusable but does not open the list.

```typescript title="multi-select-states.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { MultiSelect } from '@vigdx/ui/multi-select';

import { SKILLS } from './options';

@Component({
  selector: 'app-multi-select-states',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [MultiSelect],
  template: `
    <div class="grid gap-4 sm:grid-cols-2">
      <vig-multi-select
        label="Skills"
        labelPosition="top"
        placeholder="Pick your skills"
        hint="Shown on your public profile."
        [options]="skills"
      />
      <vig-multi-select
        label="Skills"
        labelPosition="top"
        placeholder="Pick your skills"
        [options]="skills"
        [required]="true"
        [touched]="true"
        [invalid]="true"
        [errors]="[{ kind: 'required' }]"
        [errorMessages]="{ required: 'Pick at least one skill.' }"
      />
      <vig-multi-select
        label="Disabled"
        [options]="skills"
        [value]="['angular']"
        [disabled]="true"
      />
      <vig-multi-select
        label="Read-only"
        [options]="skills"
        [value]="['angular', 'css']"
        [readonly]="true"
      />
    </div>
    <div class="grid gap-4 sm:grid-cols-3">
      <vig-multi-select label="Small" size="sm" [options]="skills" [value]="['sql']" />
      <vig-multi-select label="Medium" size="md" [options]="skills" [value]="['sql']" />
      <vig-multi-select label="Large" size="lg" [options]="skills" [value]="['sql']" />
    </div>
  `,
})
export class MultiSelectStatesDemo {
  protected readonly skills = SKILLS;
}
```

```typescript title="options.ts"
import type { SelectOption } from '@vigdx/ui/select';

export const SKILLS: SelectOption[] = [
  { value: 'angular', label: 'Angular' },
  { value: 'typescript', label: 'TypeScript' },
  { value: 'rxjs', label: 'RxJS' },
  { value: 'css', label: 'CSS' },
  { value: 'a11y', label: 'Accessibility' },
  { value: 'node', label: 'Node.js' },
  { value: 'sql', label: 'SQL' },
  { value: 'go', label: 'Go', disabled: true },
];

export const COUNTRIES: SelectOption[] = [
  { value: 'de', label: 'Germany' },
  { value: 'fr', label: 'France' },
  { value: 'it', label: 'Italy' },
  { value: 'nl', label: 'Netherlands' },
  { value: 'pl', label: 'Poland' },
  { value: 'es', label: 'Spain' },
  { value: 'se', label: 'Sweden' },
  { value: 'tr', label: 'Türkiye' },
];
```

## Reactive Forms

Import `VigValueAccessor` next to the component to use `formControlName`, `[formControl]` or `ngModel`. Type the control as an array; `Validators.required` treats `[]` as missing.

```typescript title="multi-select-reactive-forms.ts"
import { JsonPipe } from '@angular/common';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { Button } from '@vigdx/ui/button';
import { VigValueAccessor } from '@vigdx/ui/core';
import { MultiSelect } from '@vigdx/ui/multi-select';

import { COUNTRIES, SKILLS } from './options';

@Component({
  selector: 'app-multi-select-reactive-forms',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [JsonPipe, ReactiveFormsModule, Button, MultiSelect, VigValueAccessor],
  template: `
    <form class="flex flex-col gap-4" [formGroup]="form" (ngSubmit)="submit()">
      <div class="grid gap-4 sm:grid-cols-2">
        <vig-multi-select label="Skills" formControlName="skills" [options]="skills" />
        <vig-multi-select
          label="Markets"
          display="chip"
          formControlName="markets"
          [options]="countries"
        />
      </div>
      <div class="flex gap-2">
        <vig-button type="submit" label="Save" />
        <vig-button label="Reset" variant="secondary" (click)="form.reset()" />
      </div>
      <pre class="rounded-input bg-subtle p-3 font-mono text-xs">{{ form.value | json }}</pre>
    </form>
  `,
})
export class MultiSelectReactiveFormsDemo {
  protected readonly skills = SKILLS;
  protected readonly countries = COUNTRIES;
  protected readonly form = new FormGroup({
    // Validators.required treats an empty array as missing.
    skills: new FormControl<string[]>([], { nonNullable: true, validators: Validators.required }),
    markets: new FormControl<string[]>(['de'], { nonNullable: true }),
  });

  protected submit(): void {
    this.form.markAllAsTouched();
  }
}
```

```typescript title="options.ts"
import type { SelectOption } from '@vigdx/ui/select';

export const SKILLS: SelectOption[] = [
  { value: 'angular', label: 'Angular' },
  { value: 'typescript', label: 'TypeScript' },
  { value: 'rxjs', label: 'RxJS' },
  { value: 'css', label: 'CSS' },
  { value: 'a11y', label: 'Accessibility' },
  { value: 'node', label: 'Node.js' },
  { value: 'sql', label: 'SQL' },
  { value: 'go', label: 'Go', disabled: true },
];

export const COUNTRIES: SelectOption[] = [
  { value: 'de', label: 'Germany' },
  { value: 'fr', label: 'France' },
  { value: 'it', label: 'Italy' },
  { value: 'nl', label: 'Netherlands' },
  { value: 'pl', label: 'Poland' },
  { value: 'es', label: 'Spain' },
  { value: 'se', label: 'Sweden' },
  { value: 'tr', label: 'Türkiye' },
];
```

## Signal Forms

`vig-multi-select` implements `FormValueControl<T[]>`. Signal Forms' `required()` treats `[]` as filled, so check the length with `validate()`.

```typescript title="multi-select-signal-forms.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { FormField, form, validate } from '@angular/forms/signals';
import { MultiSelect } from '@vigdx/ui/multi-select';

import { SKILLS } from './options';

@Component({
  selector: 'app-multi-select-signal-forms',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [FormField, MultiSelect],
  template: `
    <div class="max-w-sm">
      <vig-multi-select
        label="Skills"
        hint="Pick two to four."
        display="chip"
        [options]="skills"
        [maxSelectedLabels]="4"
        [formField]="profile.skills"
      />
    </div>
    <p class="text-sm text-muted-foreground">
      Valid: {{ profile().valid() ? 'yes' : 'no' }} · {{ model().skills.length }} selected
    </p>
  `,
})
export class MultiSelectSignalFormsDemo {
  protected readonly skills = SKILLS;
  protected readonly model = signal({ skills: ['angular'] as string[] });
  // required() treats [] as filled, so validate the length instead.
  protected readonly profile = form(this.model, (path) => {
    validate(path.skills, ({ value }) => {
      const count = value().length;
      if (count < 2) return { kind: 'minItems', message: 'Pick at least two skills.' };
      if (count > 4) return { kind: 'maxItems', message: 'Pick at most four skills.' };
      return undefined;
    });
  });
}
```

```typescript title="options.ts"
import type { SelectOption } from '@vigdx/ui/select';

export const SKILLS: SelectOption[] = [
  { value: 'angular', label: 'Angular' },
  { value: 'typescript', label: 'TypeScript' },
  { value: 'rxjs', label: 'RxJS' },
  { value: 'css', label: 'CSS' },
  { value: 'a11y', label: 'Accessibility' },
  { value: 'node', label: 'Node.js' },
  { value: 'sql', label: 'SQL' },
  { value: 'go', label: 'Go', disabled: true },
];

export const COUNTRIES: SelectOption[] = [
  { value: 'de', label: 'Germany' },
  { value: 'fr', label: 'France' },
  { value: 'it', label: 'Italy' },
  { value: 'nl', label: 'Netherlands' },
  { value: 'pl', label: 'Poland' },
  { value: 'es', label: 'Spain' },
  { value: 'se', label: 'Sweden' },
  { value: 'tr', label: 'Türkiye' },
];
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="multi-select"][data-part="field"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="multi-select"]`

| Part | Element | data-state |
| --- | --- | --- |
| `field` | Positioned wrapper of the label, trigger and buttons. |   |
| `label` | The visible (or floating) label. |   |
| `trigger` | The `role="combobox"` element. | `open, closed` |
| `value` | The comma list or "{0} selected" summary. |   |
| `chip` | A `vig-chip` per selected option (`display="chip"`). |   |
| `placeholder` | The placeholder text in the trigger. |   |
| `indicator` | The chevron. |   |
| `clear` | The clear button (`clearable`). |   |
| `panel` | The overlay panel, rendered in the overlay container. |   |
| `listbox` | The `role="listbox"` list inside the panel. |   |
| `option` | One option (`aria-selected`, `aria-disabled`). |   |
| `empty` | The "no results" row. |   |
| `filter` | The search field at the top of the panel (`filter`). |   |
| `select-all` | The select-all toggle (`showSelectAll`). |   |
| `hint` | The `vig-hint` (a `display: contents` host; style its `text` part). |   |
| `disabled-reason` | The `vig-hint` with the disabled reason (`display: contents`). |   |
| `error` | The `vig-field-error` (a `display: contents` host; style its `message` part). |   |

## Accessibility

- The field is a `role="combobox"` controlling a `role="listbox"` with `aria-multiselectable="true"`; each option reports its state with `aria-selected`.
- Focus stays on the field and the highlighted option is exposed through `aria-activedescendant` and drawn with an outline that forced-colors mode keeps. With `filter`, the trigger opens a labelled `role="dialog"` (`aria-haspopup="dialog"`) holding the filter box, itself a combobox (`aria-autocomplete="list"`) driving the list. The arrows, Home and End move; Enter or Space toggle the option; Escape closes; typing jumps to a matching label.
- Chip remove buttons are named "Remove" plus the option label by default (`removeAriaLabel`); the select-all row is a button with `aria-pressed`.
- The field is named by its `label`, also with `hideLabel`; hint and error are linked through `aria-describedby` and an invalid field sets `aria-invalid="true"`.

## API

### MultiSelect

Selector: `vig-multi-select` · Kind: component

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `ariaLabel` | `string \| undefined` | `undefined` | — |
| `chipRemoveAriaLabel` | `string \| undefined` | `undefined` | **Deprecated**: Use `removeAriaLabel`; still honored when `removeAriaLabel` is unset. |
| `clearable` | `boolean` | `false` | — |
| `clearAriaLabel` | `string \| undefined` | `undefined` | — |
| `dirty` | `boolean` | `false` | — |
| `disabled` | `boolean` | `false` | — |
| `disabledReasons` | `readonly WithOptionalFieldTree<DisabledReason>[]` | `[]` | — |
| `display` | `"comma" \| "chip"` | `'comma'` | 'comma' joins the labels; 'chip' renders removable chips. |
| `emptyMessage` | `string \| undefined` | `undefined` | — |
| `errorMessages` | `Record<string, string>` | — | — |
| `errors` | `readonly ValidationError.WithOptionalFieldTree[]` | `[]` | — |
| `filter` | `boolean` | `false` | — |
| `filterAriaLabel` | `string \| undefined` | `undefined` | — |
| `filterPlaceholder` | `string \| undefined` | `undefined` | — |
| `hidden` | `boolean` | `false` | — |
| `hideLabel` | `boolean` | `false` | Visually hides the label — it still names the control for assistive tech — and drops the row reserved for it, giving a shorter control for dense toolbars such as table filters. Pair it with a placeholder. |
| `hint` | `string \| undefined` | `undefined` | — |
| `invalid` | `boolean` | `false` | — |
| `label` (required) | `string` | — | — |
| `labelPosition` | `LabelPosition` | `'float'` | `float` (default) rests the label inside the field; `top` sets it above a shorter field, for forms laid out with labels over their controls. |
| `maxSelectedLabels` | `number` | `3` | Above this count the trigger shows `selectedItemsLabel` instead. |
| `name` | `string` | `''` | — |
| `options` | `readonly SelectOption<T>[]` | `[]` | — |
| `pending` | `boolean` | `false` | — |
| `placeholder` | `string \| undefined` | `undefined` | — |
| `readonly` | `boolean` | `false` | — |
| `removeAriaLabel` | `string \| undefined` | `undefined` | Prefix for each chip's remove button name (i18n); the option label is appended. |
| `required` | `boolean` | `false` | — |
| `selectAllLabel` | `string \| undefined` | `undefined` | — |
| `selectedItemsLabel` | `string \| undefined` | `undefined` | `{0}` is replaced with the selection count. |
| `showSelectAll` | `boolean` | `false` | — |
| `size` | `FieldSize` | `'md'` | — |
| `touched` | `boolean` | `false` | — |
| `value` (model) | `T[]` | `[]` | — |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `touch` | `void` | — |
| `valueChange` | `T[]` | — |

#### Methods

| Signature | Description |
| --- | --- |
| `focus(options?: FocusOptions): void` | Moves focus to the control's interactive element (the input, or the trigger of a popup control). Signal Forms calls it through `field().focusBoundControl()`; the host element itself cannot take focus. |
| `isSelected(value: T): boolean` | — |
| `reset(): void` | Closes the panel without moving focus or marking the field touched; see `VigFormField.reset`. |

### SelectOptionTemplate

Selector: `ng-template[vigSelectOption]` · Kind: directive

Custom rendering for options of `vig-select`, `vig-multi-select`, `vig-listbox` and `vig-select-button`, replacing the default icon + label. `vig-select` also uses it for the selected value shown in the trigger.

Bind the same options to `vigSelectOptionOf` (like `ngForOf`) to type `let-option` in the template; without it the option value is `unknown`.

**Example :**

```html
<vig-select label="Status" [options]="statuses">
  <ng-template vigSelectOption [vigSelectOptionOf]="statuses" let-option>
    <i [class]="option.value" aria-hidden="true"></i> {{ option.label }}
  </ng-template>
</vig-select>
```

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `vigSelectOptionOf` | `readonly SelectOption<T>[] \| null \| undefined` | `undefined` | Type-only: the options the template renders, so the template type checker infers the option value type. Not read at runtime. |

### VigValueAccessor

Kind: directive

Bridges the vigdx form fields to Reactive Forms (`formControl`, `formControlName`) and template-driven forms (`ngModel`). Import it next to the component; Signal Forms (`[formField]`) need no accessor.

#### Methods

| Signature | Description |
| --- | --- |
| `registerOnChange(fn: (value: unknown) => void): void` | — |
| `registerOnTouched(fn: () => void): void` | — |
| `setDisabledState(disabled: boolean): void` | — |
| `writeValue(value: unknown): void` | — |
