Skip to content

Commit bcf58e5

Browse files
committed
fix(material/select): open handler invoked twice
Fixes that the select's `open` handler was being called twice: once from the trigger's `click` handler and once from the `onContainerClick` callback when the event propagates. Fixes #33116.
1 parent 91a4932 commit bcf58e5

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

goldens/material/select/index.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit
361361
tabIndex: number;
362362
toggle(): void;
363363
trigger: ElementRef;
364+
// (undocumented)
365+
protected _triggerClicked(): void;
364366
get triggerValue(): string;
365367
typeaheadDebounceInterval: number;
366368
updateErrorState(): void;

src/material/select/select.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div
22
cdk-overlay-origin
33
class="mat-mdc-select-trigger"
4-
(click)="open()"
4+
(click)="_triggerClicked()"
55
#fallbackOverlayOrigin="cdkOverlayOrigin"
66
#trigger
77
>

src/material/select/select.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,13 @@ export class MatSelect
10181018
return !this._selectionModel || this._selectionModel.isEmpty();
10191019
}
10201020

1021+
protected _triggerClicked() {
1022+
// If a parent form field is present, it'll pick up this click so we don't need to handle it.
1023+
if (!this._parentFormField) {
1024+
this.open();
1025+
}
1026+
}
1027+
10211028
private _initializeSelection(): void {
10221029
// Defer setting the value in order to avoid the "Expression
10231030
// has changed after it was checked" errors from Angular.

0 commit comments

Comments
 (0)