Skip to content

Commit 8d79d73

Browse files
crisbetommalerba
authored andcommitted
fix(autocomplete): incorrectly detecting shadow DOM when inserted through an embedded view (#19332)
1 parent c17b150 commit 8d79d73

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
228228
const window = this._getWindow();
229229

230230
if (typeof window !== 'undefined') {
231-
this._zone.runOutsideAngular(() => {
232-
window.addEventListener('blur', this._windowBlurHandler);
233-
});
234-
235-
this._isInsideShadowRoot = !!_getShadowRoot(this._element.nativeElement);
231+
this._zone.runOutsideAngular(() => window.addEventListener('blur', this._windowBlurHandler));
236232
}
237233
}
238234

@@ -619,6 +615,12 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
619615
throw getMatAutocompleteMissingPanelError();
620616
}
621617

618+
// We want to resolve this once, as late as possible so that we can be
619+
// sure that the element has been moved into its final place in the DOM.
620+
if (this._isInsideShadowRoot == null) {
621+
this._isInsideShadowRoot = !!_getShadowRoot(this._element.nativeElement);
622+
}
623+
622624
let overlayRef = this._overlayRef;
623625

624626
if (!overlayRef) {

0 commit comments

Comments
 (0)