Skip to content

Commit bd9500d

Browse files
committed
refactor(autocomplete): rework cases not using document token
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 ae41a0a commit bd9500d

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

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

163163
/** `View -> model callback called when value changes` */
@@ -318,10 +318,6 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
318318

319319
/** Stream of clicks outside of the autocomplete panel. */
320320
private _getOutsideClickStream(): Observable<any> {
321-
if (!this._document) {
322-
return observableOf(null);
323-
}
324-
325321
return merge(
326322
fromEvent<MouseEvent>(this._document, 'click'),
327323
fromEvent<TouchEvent>(this._document, 'touchend')
@@ -407,7 +403,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
407403
this._previousValue = value;
408404
this._onChange(value);
409405

410-
if (this._canOpen() && document.activeElement === event.target) {
406+
if (this._canOpen() && this._document.activeElement === event.target) {
411407
this.openPanel();
412408
}
413409
}

0 commit comments

Comments
 (0)