Skip to main content

Overview

<mat-select> is a form control for selecting a value from a set of options, similar to the native <select> element. It is designed to work inside of a <mat-form-field> element.

Basic Usage

<mat-form-field>
  <mat-label>Choose an option</mat-label>
  <mat-select>
    <mat-option value="option1">Option 1</mat-option>
    <mat-option value="option2">Option 2</mat-option>
    <mat-option value="option3">Option 3</mat-option>
  </mat-select>
</mat-form-field>

API Reference

MatSelect

Selector: mat-select Exported as: matSelect

Inputs

disabled
boolean
default:"false"
Whether the select is disabled.
disableRipple
boolean
default:"false"
Whether ripples are disabled.
tabIndex
number
default:"0"
Tab index for the select.
hideSingleSelectionIndicator
boolean
Whether checkmark indicator for single-selection options is hidden.
placeholder
string
Placeholder to be shown if no value has been selected.
required
boolean
default:"false"
Whether the component is required.
multiple
boolean
default:"false"
Whether the user should be allowed to select multiple options.
disableOptionCentering
boolean
default:"false"
Whether to center the active option over the trigger.
compareWith
(o1: any, o2: any) => boolean
Function to compare the option values with the selected values.
value
any
Value of the select control.
panelClass
string | string[]
Classes to be passed to the select panel.
id
string
Unique id of the element.
errorStateMatcher
ErrorStateMatcher
Object used to control when error messages are shown.
typeaheadDebounceInterval
number
default:"200"
Time to wait in milliseconds after the last keystroke before moving focus to an item.

Outputs

openedChange
EventEmitter<boolean>
Event emitted when the select panel has been toggled.
opened
EventEmitter<void>
Event emitted when the select panel has been opened.
closed
EventEmitter<void>
Event emitted when the select panel has been closed.
selectionChange
EventEmitter<MatSelectChange>
Event emitted when the selected value has been changed by the user.

Methods

focus()
void
Focuses the select element.
open()
void
Opens the select’s panel.
close()
void
Closes the select’s panel.
toggle()
void
Toggles the select’s panel between open and closed.

MatSelectChange

source
MatSelect
Reference to the select that emitted the change event.
value
any
Current value of the select that emitted the event.

Multiple Selection

<mat-form-field>
  <mat-label>Toppings</mat-label>
  <mat-select [formControl]="toppingsControl" multiple>
    <mat-option *ngFor="let topping of toppingList" [value]="topping">
      {{ topping }}
    </mat-option>
  </mat-select>
</mat-form-field>

Option Groups

<mat-form-field>
  <mat-label>Pokemon</mat-label>
  <mat-select>
    <mat-optgroup *ngFor="let group of pokemonGroups" [label]="group.name">
      <mat-option *ngFor="let pokemon of group.pokemon" [value]="pokemon">
        {{ pokemon }}
      </mat-option>
    </mat-optgroup>
  </mat-select>
</mat-form-field>

Accessibility

  • The select uses role="combobox" with appropriate ARIA attributes
  • The select panel uses role="listbox"
  • Options use role="option"
  • Keyboard navigation is fully supported:
    • ARROW_UP/DOWN: Navigate through options
    • ENTER/SPACE: Select the focused option
    • ESCAPE: Close the panel
    • Type to search for options (typeahead)
  • Screen readers announce the selected value and option count
  • Use aria-label or ensure the select has a label via <mat-label>

Advanced Usage

Custom Trigger

<mat-form-field>
  <mat-select [formControl]="foodControl">
    <mat-select-trigger>
      {{ foodControl.value?.label }}
      <span *ngIf="foodControl.value?.emoji"> - {{ foodControl.value.emoji }}</span>
    </mat-select-trigger>
    <mat-option *ngFor="let food of foods" [value]="food">
      {{ food.emoji }} {{ food.label }}
    </mat-option>
  </mat-select>
</mat-form-field>

Disable Option Centering

By default, the select centers the active option. Disable this behavior:
<mat-select [disableOptionCentering]="true">
  <!-- options -->
</mat-select>

Custom Comparison

Provide a custom comparison function for object values:
compareObjects(o1: any, o2: any) {
  return o1.id === o2.id;
}
<mat-select [compareWith]="compareObjects">
  <!-- options -->
</mat-select>

Reset Option

<mat-form-field>
  <mat-label>State</mat-label>
  <mat-select [(value)]="selectedValue">
    <mat-option>None</mat-option>
    <mat-option value="option1">Option 1</mat-option>
    <mat-option value="option2">Option 2</mat-option>
  </mat-select>
</mat-form-field>

Error Messages

<mat-form-field>
  <mat-label>Favorite food</mat-label>
  <mat-select [formControl]="foodControl" required>
    <mat-option *ngFor="let food of foods" [value]="food">
      {{ food }}
    </mat-option>
  </mat-select>
  <mat-error *ngIf="foodControl.hasError('required')">
    Please select a food
  </mat-error>
</mat-form-field>

Build docs developers (and LLMs) love