I have a select dropdown that I want to open with a button click, there is no mention of this anywhere in the docs - I have tried using an element reference and using select.open() on the element but it doesn't work. Has anyone else run into this issue?
<button ngClass="menu-filter-item-button" type="button" mat-button (click)="select.open()">
    <strong class="menu-filter-item-title">{{filter.name}}</strong>
    <mat-icon>keyboard_arrow_down</mat-icon>
</button>
<mat-select #select multiple (change)="onSubmit($event)" [compareWith]="compareById" [(ngModel)]="filter.value">
    <mat-option *ngFor="let value of filter.default" [value]="value">
        {{value}}
    </mat-option>
</mat-select>
                I had the same problem and this dirty hack solved it without displaying the mat-select itself:
HTML:
<button
  mat-icon-button
  matTooltip="Language"
  (click)=select.open()>
  <mat-icon>language</mat-icon>
  <mat-select
    #select
    [(ngModel)]="setLang"
    class="langSelect">
    <mat-option (click)="changeLang()" value="en">English</mat-option>
    <mat-option (click)="changeLang()" value="de">Deutsch</mat-option>
  </mat-select>
</button>
CSS:
::ng-deep .langSelect div.mat-select-arrow-wrapper {
  display: none;
}
::ng-deep .langSelect.mat-select {
  display: inline;
}
In my project it looks better than on StackBlitz, but anyway here is a link to this code on StackBlitz.
If you want to to simply have an additional button that opens the mat-select too this will work for you (no css needed):
<button mat-icon-button matTooltip="Language" (click)=select.open()>
  <mat-icon>language</mat-icon>
  <mat-select #select [(ngModel)]="setLang">
    <mat-option (click)="changeLang()" value="en">English</mat-option>
    <mat-option (click)="changeLang()" value="de">Deutsch</mat-option>
  </mat-select>
</button>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With