Tableau UI for Angular

Select Dropdown

A select picks one value, or several, from a dropdown list of options.

Import

Import TableauUiSelectModule from tableau-ui-angular/select for tab-single-select and tab-multi-select, and TableauUiCommonModule from tableau-ui-angular/common for tab-option. Each is a combobox with a listbox, for the keyboard and screen readers.

Options

A tab-option takes its text, hint and icon as values or as templates, and can be disabled. Without a form, bind [value] and (valueChange); this one shows a snack on each change.

The selected value wraps and makes the control taller; its icon shows in it
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { TableauUiFormFieldModule } from 'tableau-ui-angular/form-field';
import { TableauUiSelectModule } from 'tableau-ui-angular/select';
import { SnackService } from 'tableau-ui-angular/snack';

@Component({
  selector: 'app-select-options-example',
  imports: [TableauUiCommonModule, TableauUiFormFieldModule, TableauUiSelectModule],
  templateUrl: './select-options.example.html',
  styleUrl: './select-options.example.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SelectOptionsExampleComponent {
  private readonly snacks = inject(SnackService);

  protected readonly $value = signal<number | undefined>(undefined);

  protected changed(value: number | undefined) {
    this.$value.set(value);
    this.snacks.openSnack(`Single select value changed to: ${value ?? '[none]'}`, 2000, 'info');
  }
}

How the value shows

selectedValueWrapMode wraps or cuts the value short, [selectedValueTemplateContext] leaves out its icon, selectedCheckIconLocation puts the check on the left, the right or nowhere, and [showChevron], [allowClear] and [selectedItemHighlight] turn their parts on or off. A form field's prefix and suffix sit around the select.

The selected value is cut short, shows only its text, and is checked on the right
It shows the value and opens no dropdown
A suffix
No chevron, and the value can't be cleared
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import type { IOptionLineContext } from 'tableau-ui-angular/common';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { TableauUiFormFieldModule } from 'tableau-ui-angular/form-field';
import { TableauUiIconModule } from 'tableau-ui-angular/icon';
import { TableauUiSelectModule } from 'tableau-ui-angular/select';
import { SnackService } from 'tableau-ui-angular/snack';

interface Option {
  value: number;
  text: string;
  icon?: string;
  hint?: string;
  disabled?: boolean;
}

@Component({
  selector: 'app-select-display-example',
  imports: [TableauUiCommonModule, TableauUiFormFieldModule, TableauUiIconModule, TableauUiSelectModule],
  templateUrl: './select-display.example.html',
  styleUrl: './select-display.example.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SelectDisplayExampleComponent {
  private readonly snacks = inject(SnackService);

  protected readonly options: readonly Option[] = [
    { value: 1, text: 'This is a looooooooooooooooong option, given as values', icon: 'home', hint: 'There are 2 ways to create tab-options: by values and by templates' },
    { value: 2, text: 'Disabled value', hint: 'with a hint', disabled: true },
    { value: 3, text: 'A short option', icon: 'home', hint: 'with a hint' },
  ];

  // The selected value shows its text only, without its icon
  protected readonly onlyText: IOptionLineContext = { renderIcon: false, renderText: true };

  protected readonly $value = signal<number | undefined>(1);

  protected changed(value: number | undefined) {
    this.$value.set(value);
    this.snacks.openSnack(`Single select value changed to: ${value ?? '[none]'}`, 2000, 'info');
  }
}

Reactive forms

Bind [formControl] or formControlName. The control is touched when the user leaves the select, and a disabled control disables it.

The selected value wraps and makes the control taller; its icon shows in it
The selected value is cut short and shows only its text
A disabled control disables the select
A suffix
No chevron, and the value can't be cleared
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { Validators } from '@angular/forms';
import type { IOptionLineContext } from 'tableau-ui-angular/common';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { FB, TableauUiFormModule } from 'tableau-ui-angular/form';
import { TableauUiFormFieldModule } from 'tableau-ui-angular/form-field';
import { TableauUiIconModule } from 'tableau-ui-angular/icon';
import { TableauUiSelectModule } from 'tableau-ui-angular/select';

interface Option {
  value: number;
  text: string;
  icon?: string;
  hint?: string;
  disabled?: boolean;
}

@Component({
  selector: 'app-select-forms-example',
  imports: [TableauUiCommonModule, TableauUiFormModule, TableauUiFormFieldModule, TableauUiIconModule, TableauUiSelectModule],
  templateUrl: './select-forms.example.html',
  styleUrl: './select-forms.example.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SelectFormsExampleComponent {
  private readonly fb = inject(FB);

  protected readonly options: readonly Option[] = [
    { value: 1, text: 'This is a looooooooooooooooong option, given as values', icon: 'home', hint: 'There are 2 ways to create tab-options: by values and by templates' },
    { value: 2, text: 'Disabled value', hint: 'with a hint', disabled: true },
    { value: 3, text: 'Option 3', icon: 'home', hint: 'with a hint' },
    { value: 4, text: 'Option 4, above the maximum', icon: 'home', hint: 'The validators allow 1 to 3' },
  ];

  protected readonly onlyText: IOptionLineContext = { renderIcon: false, renderText: true };

  // Each starts at 4, above Validators.max(3): its error shows once the user leaves the select, as formHasError waits
  // for the control to be touched
  private readonly validators = [Validators.required, Validators.min(1), Validators.max(3)];
  protected readonly wrap = this.fb.control<number | null>(4, this.validators);
  protected readonly truncate = this.fb.control<number | null>(4, this.validators);
  protected readonly noChevron = this.fb.control<number | null>(4, this.validators);
  // the fourth argument starts the control disabled
  protected readonly disabled = this.fb.control<number | null>(2, undefined, undefined, true);
}

Multiple values

tab-multi-select holds an array. [multipleSelectionMaxItemsListed] caps how many it lists before multipleSelectionNumberSelectedTemplate says how many there are, and [dropdownOptionsContainerCss] styles the list.

With more than 2 picked, it says how many
The selected values are cut short; the dropdown scrolls
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Validators } from '@angular/forms';
import { skip } from 'rxjs';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { FB, TableauUiFormModule } from 'tableau-ui-angular/form';
import { TableauUiFormFieldModule } from 'tableau-ui-angular/form-field';
import { TableauUiSelectModule } from 'tableau-ui-angular/select';
import { SnackService } from 'tableau-ui-angular/snack';

@Component({
  selector: 'app-select-multi-example',
  imports: [TableauUiCommonModule, TableauUiFormModule, TableauUiFormFieldModule, TableauUiSelectModule],
  templateUrl: './select-multi.example.html',
  styleUrl: './select-multi.example.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SelectMultiExampleComponent {
  private readonly fb = inject(FB);
  private readonly snacks = inject(SnackService);

  // Both selects share this control, so a pick in one shows in the other
  protected readonly values = this.fb.control<number[] | null>([1, 3], [Validators.required]);

  constructor() {
    this.values.value$.pipe(skip(1), takeUntilDestroyed()).subscribe(values => {
      this.snacks.openSnack(`Multi select value changed to: ${values?.join(', ') ?? '[none]'}`, 2000, 'info');
    });
  }
}

A search in the dropdown

A tab-prefix and a tab-suffix inside the select sit above and below its options: here a search box, a loading spinner and the count.

The prefix holds the search box; the options are what it finds
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { debounceTime, Subject } from 'rxjs';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { TableauUiFormFieldModule } from 'tableau-ui-angular/form-field';
import { TableauUiIconModule } from 'tableau-ui-angular/icon';
import { TableauUiSelectModule } from 'tableau-ui-angular/select';

const USERS = [
  'John Smith',
  'Jane Doe',
  'Michael Johnson',
  'Emily Davis',
  'William Brown',
  'Olivia Wilson',
  'James Taylor',
  'Sophia Martinez',
  'Benjamin Lee',
  'Isabella Anderson',
  'Henry Thomas',
  'Mia Jackson',
  'Daniel White',
  'Charlotte Harris',
  'Matthew Clark',
  'Amelia Lewis',
  'Andrew Walker',
  'Harper Young',
  'David Hall',
  'Evelyn Allen',
].map((name, index) => ({ id: index + 1, name }));

@Component({
  selector: 'app-select-search-example',
  imports: [ReactiveFormsModule, TableauUiCommonModule, TableauUiFormFieldModule, TableauUiIconModule, TableauUiSelectModule],
  templateUrl: './select-search.example.html',
  styleUrl: './select-search.example.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SelectSearchExampleComponent {
  protected readonly users = new FormControl<number[]>([], { nonNullable: true });

  protected readonly $search = signal('');
  protected readonly $searching = signal(false);
  protected readonly $results = signal(USERS);
  protected readonly $count = computed(() => this.$results().length);

  private readonly typed = new Subject<string>();

  constructor() {
    // A search that takes a second, as a server's would, once the user stops typing
    this.typed.pipe(debounceTime(300), takeUntilDestroyed()).subscribe(search => {
      this.$searching.set(true);
      setTimeout(() => {
        const words = search.toLowerCase().split(' ');
        this.$results.set(USERS.filter(user => words.every(word => user.name.toLowerCase().includes(word))));
        this.$searching.set(false);
      }, 1000);
    });
  }

  protected input(event: Event) {
    const { value } = event.target as HTMLInputElement;
    this.$search.set(value);
    this.typed.next(value);
  }
}