Skip to content

Commit

Permalink
fix(autocomplete): incorrectly detecting shadow DOM when inserted thr…
Browse files Browse the repository at this point in the history
…ough an embedded view

When an autocomplete is inserted, we try to figure out whether it's in the shadow DOM so that we can handle outside clicks properly. It seems like our logic can run too early in some cases, causing it to be detected incorrectly. These changes move the logic later in the process, right before the overlay is attached to the DOM.

Fixes #19330.
  • Loading branch information
crisbeto committed May 12, 2020
1 parent eb218e5 commit d93406c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/material/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
const window = this._getWindow();

if (typeof window !== 'undefined') {
this._zone.runOutsideAngular(() => {
window.addEventListener('blur', this._windowBlurHandler);
});

this._isInsideShadowRoot = !!_getShadowRoot(this._element.nativeElement);
this._zone.runOutsideAngular(() => window.addEventListener('blur', this._windowBlurHandler));
}
}

Expand Down Expand Up @@ -619,6 +615,12 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
throw getMatAutocompleteMissingPanelError();
}

// We want to resolve this once, as late as possible so that we can be
// sure that the element has been moved into its final place in the DOM.
if (this._isInsideShadowRoot == null) {
this._isInsideShadowRoot = !!_getShadowRoot(this._element.nativeElement);
}

let overlayRef = this._overlayRef;

if (!overlayRef) {
Expand Down

0 comments on commit d93406c

Please sign in to comment.