Skip to content

Commit

Permalink
fix(material/select): flicker if opened from inside a focus handler (#…
Browse files Browse the repository at this point in the history
…28287)

Fixes that the select was closing and reopening if it's opened from inside a `focus` handler on click. Also avoids a bit of work in the `open` and `close` methods.

Fixes #28280.
  • Loading branch information
crisbeto authored Dec 15, 2023
1 parent df8b86a commit 1b6db8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/material/select/select.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div cdk-overlay-origin
class="mat-mdc-select-trigger"
(click)="toggle()"
(click)="open()"
#fallbackOverlayOrigin="cdkOverlayOrigin"
#trigger>

Expand Down
22 changes: 11 additions & 11 deletions src/material/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,10 @@ export class MatSelect

/** Opens the overlay panel. */
open(): void {
if (!this._canOpen()) {
return;
}

// It's important that we read this as late as possible, because doing so earlier will
// return a different element since it's based on queries in the form field which may
// not have run yet. Also this needs to be assigned before we measure the overlay width.
Expand All @@ -734,15 +738,12 @@ export class MatSelect
}

this._overlayWidth = this._getOverlayWidth(this._preferredOverlayOrigin);
this._applyModalPanelOwnership();
this._panelOpen = true;
this._keyManager.withHorizontalOrientation(null);
this._highlightCorrectOption();
this._changeDetectorRef.markForCheck();

if (this._canOpen()) {
this._applyModalPanelOwnership();

this._panelOpen = true;
this._keyManager.withHorizontalOrientation(null);
this._highlightCorrectOption();
this._changeDetectorRef.markForCheck();
}
// Required for the MDC form field to pick up when the overlay has been opened.
this.stateChanges.next();
}
Expand Down Expand Up @@ -819,10 +820,9 @@ export class MatSelect
this._keyManager.withHorizontalOrientation(this._isRtl() ? 'rtl' : 'ltr');
this._changeDetectorRef.markForCheck();
this._onTouched();
// Required for the MDC form field to pick up when the overlay has been closed.
this.stateChanges.next();
}

// Required for the MDC form field to pick up when the overlay has been closed.
this.stateChanges.next();
}

/**
Expand Down

0 comments on commit 1b6db8c

Please sign in to comment.