Skip to content

Commit fbda157

Browse files
volvachevEgor Volvachev
authored and
Egor Volvachev
committed
fix(material/autocomplete): outside click in Angular zone.
Fixes a bug in Angular Material `autocomplete` when outside click doesn't trigger `changeDetection`. Fixes #24811
1 parent c6a1d15 commit fbda157

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,16 @@ export abstract class _MatAutocompleteTriggerBase
268268

269269
if (this.panelOpen) {
270270
// Only emit if the panel was visible.
271-
this.autocomplete.closed.emit();
271+
// The `NgZone.onStable` always emits outside of the Angular zone,
272+
// so all the subscriptions from `_subscribeToClosingActions()` are also outside of the Angular zone.
273+
// We should manually run in Angular zone to update UI after panel closing.
274+
if (NgZone.isInAngularZone()) {
275+
this.autocomplete.closed.emit();
276+
} else {
277+
this._zone.run(() => {
278+
this.autocomplete.closed.emit();
279+
});
280+
}
272281
}
273282

274283
this.autocomplete._isOpen = this._overlayAttached = false;

0 commit comments

Comments
 (0)