Skip to content

Commit 07e8028

Browse files
crisbetojelbourn
authored andcommitted
refactor(autocomplete): rework cases not using document token (#15366)
Fixes a couple of places that were referring to the global `document` variable, rather than using the token. These could potentially throw on the server, if a code path somehow hit them.
1 parent 28743f1 commit 07e8028

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnChanges,
160160
// refocused when they come back. In this case we want to skip the first focus event, if the
161161
// pane was closed, in order to avoid reopening it unintentionally.
162162
this._canOpenOnNextFocus =
163-
document.activeElement !== this._element.nativeElement || this.panelOpen;
163+
this._document.activeElement !== this._element.nativeElement || this.panelOpen;
164164
}
165165

166166
/** `View -> model callback called when value changes` */
@@ -340,10 +340,6 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnChanges,
340340

341341
/** Stream of clicks outside of the autocomplete panel. */
342342
private _getOutsideClickStream(): Observable<any> {
343-
if (!this._document) {
344-
return observableOf(null);
345-
}
346-
347343
return merge(
348344
fromEvent(this._document, 'click') as Observable<MouseEvent>,
349345
fromEvent(this._document, 'touchend') as Observable<TouchEvent>
@@ -429,7 +425,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnChanges,
429425
this._previousValue = value;
430426
this._onChange(value);
431427

432-
if (this._canOpen() && document.activeElement === event.target) {
428+
if (this._canOpen() && this._document.activeElement === event.target) {
433429
this.openPanel();
434430
}
435431
}

0 commit comments

Comments
 (0)