Skip to content

Commit 7f278ad

Browse files
jelbourntinayuangao
authored andcommitted
Revert "refactor: avoid casting document to any in constructor (#10775)" (#10824)
This reverts commit e60f5fc.
1 parent f1a33e9 commit 7f278ad

File tree

18 files changed

+57
-30
lines changed

18 files changed

+57
-30
lines changed

src/cdk-experimental/dialog/dialog-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class CdkDialogContainer extends BasePortalOutlet {
109109
private _elementRef: ElementRef,
110110
private _focusTrapFactory: FocusTrapFactory,
111111
private _changeDetectorRef: ChangeDetectorRef,
112-
@Optional() @Inject(DOCUMENT) private _document: Document) {
112+
@Optional() @Inject(DOCUMENT) private _document: any) {
113113
super();
114114
}
115115

src/cdk/a11y/aria-describer/aria-describer.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ let messagesContainer: HTMLElement | null = null;
5555
*/
5656
@Injectable({providedIn: 'root'})
5757
export class AriaDescriber {
58-
constructor(@Inject(DOCUMENT) private _document: Document) {}
58+
private _document: Document;
59+
60+
constructor(@Inject(DOCUMENT) _document: any) {
61+
this._document = _document;
62+
}
5963

6064
/**
6165
* Adds to the host element an aria-describedby reference to a hidden element that contains
@@ -209,8 +213,7 @@ export class AriaDescriber {
209213

210214

211215
/** @docs-private @deprecated @deletion-target 7.0.0 */
212-
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber,
213-
_document: Document) {
216+
export function ARIA_DESCRIBER_PROVIDER_FACTORY(parentDispatcher: AriaDescriber, _document: any) {
214217
return parentDispatcher || new AriaDescriber(_document);
215218
}
216219

@@ -220,7 +223,7 @@ export const ARIA_DESCRIBER_PROVIDER = {
220223
provide: AriaDescriber,
221224
deps: [
222225
[new Optional(), new SkipSelf(), AriaDescriber],
223-
DOCUMENT as InjectionToken<Document>
226+
DOCUMENT as InjectionToken<any>
224227
],
225228
useFactory: ARIA_DESCRIBER_PROVIDER_FACTORY
226229
};

src/cdk/a11y/focus-trap/focus-trap.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,15 @@ export class FocusTrap {
285285
/** Factory that allows easy instantiation of focus traps. */
286286
@Injectable({providedIn: 'root'})
287287
export class FocusTrapFactory {
288+
private _document: Document;
289+
288290
constructor(
289291
private _checker: InteractivityChecker,
290292
private _ngZone: NgZone,
291-
@Inject(DOCUMENT) private _document: Document) {}
293+
@Inject(DOCUMENT) _document: any) {
294+
295+
this._document = _document;
296+
}
292297

293298
/**
294299
* Creates a focus-trapped region around the given element.
@@ -309,6 +314,8 @@ export class FocusTrapFactory {
309314
exportAs: 'cdkTrapFocus',
310315
})
311316
export class CdkTrapFocus implements OnDestroy, AfterContentInit {
317+
private _document: Document;
318+
312319
/** Underlying FocusTrap instance. */
313320
focusTrap: FocusTrap;
314321

@@ -332,7 +339,7 @@ export class CdkTrapFocus implements OnDestroy, AfterContentInit {
332339
constructor(
333340
private _elementRef: ElementRef,
334341
private _focusTrapFactory: FocusTrapFactory,
335-
@Inject(DOCUMENT) private _document: Document) {
342+
@Inject(DOCUMENT) _document: any) {
336343

337344
this._document = _document;
338345
this.focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement, true);

src/cdk/a11y/live-announcer/live-announcer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class LiveAnnouncer implements OnDestroy {
2727

2828
constructor(
2929
@Optional() @Inject(LIVE_ANNOUNCER_ELEMENT_TOKEN) elementToken: any,
30-
@Inject(DOCUMENT) private _document: Document) {
30+
@Inject(DOCUMENT) private _document: any) {
3131

3232
// We inject the live element as `any` because the constructor signature cannot reference
3333
// browser globals (HTMLElement) on non-browser environments, since having a class decorator
@@ -83,7 +83,7 @@ export class LiveAnnouncer implements OnDestroy {
8383

8484
/** @docs-private @deprecated @deletion-target 7.0.0 */
8585
export function LIVE_ANNOUNCER_PROVIDER_FACTORY(
86-
parentDispatcher: LiveAnnouncer, liveElement: any, _document: Document) {
86+
parentDispatcher: LiveAnnouncer, liveElement: any, _document: any) {
8787
return parentDispatcher || new LiveAnnouncer(liveElement, _document);
8888
}
8989

src/cdk/overlay/keyboard/overlay-keyboard-dispatcher.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ export class OverlayKeyboardDispatcher implements OnDestroy {
2929
/** Currently attached overlays in the order they were attached. */
3030
_attachedOverlays: OverlayRef[] = [];
3131

32+
private _document: Document;
3233
private _isAttached: boolean;
3334

34-
constructor(@Inject(DOCUMENT) private _document: Document) {}
35+
constructor(@Inject(DOCUMENT) document: any) {
36+
this._document = document;
37+
}
3538

3639
ngOnDestroy() {
3740
this._detach();
@@ -94,7 +97,7 @@ export class OverlayKeyboardDispatcher implements OnDestroy {
9497

9598
/** @docs-private @deprecated @deletion-target 7.0.0 */
9699
export function OVERLAY_KEYBOARD_DISPATCHER_PROVIDER_FACTORY(
97-
dispatcher: OverlayKeyboardDispatcher, _document: Document) {
100+
dispatcher: OverlayKeyboardDispatcher, _document: any) {
98101
return dispatcher || new OverlayKeyboardDispatcher(_document);
99102
}
100103

@@ -108,7 +111,7 @@ export const OVERLAY_KEYBOARD_DISPATCHER_PROVIDER = {
108111

109112
// Coerce to `InjectionToken` so that the `deps` match the "shape"
110113
// of the type expected by Angular
111-
DOCUMENT as InjectionToken<Document>
114+
DOCUMENT as InjectionToken<any>
112115
],
113116
useFactory: OVERLAY_KEYBOARD_DISPATCHER_PROVIDER_FACTORY
114117
};

src/cdk/overlay/overlay-container.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
export class OverlayContainer implements OnDestroy {
2323
protected _containerElement: HTMLElement;
2424

25-
constructor(@Inject(DOCUMENT) private _document: Document) {}
25+
constructor(@Inject(DOCUMENT) private _document: any) {}
2626

2727
ngOnDestroy() {
2828
if (this._containerElement && this._containerElement.parentNode) {
@@ -57,7 +57,7 @@ export class OverlayContainer implements OnDestroy {
5757

5858
/** @docs-private @deprecated @deletion-target 7.0.0 */
5959
export function OVERLAY_CONTAINER_PROVIDER_FACTORY(parentContainer: OverlayContainer,
60-
_document: Document) {
60+
_document: any) {
6161
return parentContainer || new OverlayContainer(_document);
6262
}
6363

@@ -67,8 +67,7 @@ export const OVERLAY_CONTAINER_PROVIDER = {
6767
provide: OverlayContainer,
6868
deps: [
6969
[new Optional(), new SkipSelf(), OverlayContainer],
70-
// We need to use the InjectionToken somewhere to keep TS happy
71-
DOCUMENT as InjectionToken<Document>
70+
DOCUMENT as InjectionToken<any> // We need to use the InjectionToken somewhere to keep TS happy
7271
],
7372
useFactory: OVERLAY_CONTAINER_PROVIDER_FACTORY
7473
};

src/cdk/overlay/overlay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class Overlay {
5151
private _appRef: ApplicationRef,
5252
private _injector: Injector,
5353
private _ngZone: NgZone,
54-
@Inject(DOCUMENT) private _document: Document,
54+
@Inject(DOCUMENT) private _document: any,
5555
private _directionality: Directionality) { }
5656

5757
/**

src/cdk/overlay/position/overlay-position-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {GlobalPositionStrategy} from './global-position-strategy';
2020
export class OverlayPositionBuilder {
2121
constructor(
2222
private _viewportRuler: ViewportRuler,
23-
@Inject(DOCUMENT) private _document: Document) { }
23+
@Inject(DOCUMENT) private _document: any) { }
2424

2525
/**
2626
* Creates a global position strategy.

src/cdk/overlay/scroll/block-scroll-strategy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ export class BlockScrollStrategy implements ScrollStrategy {
1717
private _previousHTMLStyles = { top: '', left: '' };
1818
private _previousScrollPosition: { top: number, left: number };
1919
private _isEnabled = false;
20+
private _document: Document;
2021

21-
constructor(private _viewportRuler: ViewportRuler, private _document: Document) {}
22+
constructor(private _viewportRuler: ViewportRuler, document: any) {
23+
this._document = document;
24+
}
2225

2326
/** Attaches this scroll strategy to an overlay. */
2427
attach() { }

src/cdk/overlay/scroll/scroll-strategy-options.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ import {
2626
*/
2727
@Injectable({providedIn: 'root'})
2828
export class ScrollStrategyOptions {
29+
private _document: Document;
30+
2931
constructor(
3032
private _scrollDispatcher: ScrollDispatcher,
3133
private _viewportRuler: ViewportRuler,
3234
private _ngZone: NgZone,
33-
@Inject(DOCUMENT) private _document: Document) {}
35+
@Inject(DOCUMENT) document: any) {
36+
this._document = document;
37+
}
3438

3539
/** Do nothing on scroll. */
3640
noop = () => new NoopScrollStrategy();

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
145145
@Inject(MAT_AUTOCOMPLETE_SCROLL_STRATEGY) private _scrollStrategy,
146146
@Optional() private _dir: Directionality,
147147
@Optional() @Host() private _formField: MatFormField,
148-
@Optional() @Inject(DOCUMENT) private _document: Document,
148+
@Optional() @Inject(DOCUMENT) private _document: any,
149149
// @deletion-target 7.0.0 Make `_viewportRuler` required.
150150
private _viewportRuler?: ViewportRuler) {}
151151

src/lib/badge/badge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class MatBadge implements OnDestroy {
9696
private _badgeElement: HTMLElement;
9797

9898
constructor(
99-
@Optional() @Inject(DOCUMENT) private _document: Document,
99+
@Optional() @Inject(DOCUMENT) private _document: any,
100100
private _ngZone: NgZone,
101101
private _elementRef: ElementRef,
102102
private _ariaDescriber: AriaDescriber) {}

src/lib/bottom-sheet/bottom-sheet-container.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ export class MatBottomSheetContainer extends BasePortalOutlet implements OnDestr
7979
/** Element that was focused before the bottom sheet was opened. */
8080
private _elementFocusedBeforeOpened: HTMLElement | null = null;
8181

82+
/** Server-side rendering-compatible reference to the global document object. */
83+
private _document: Document;
84+
8285
/** Whether the component has been destroyed. */
8386
private _destroyed: boolean;
8487

@@ -87,9 +90,10 @@ export class MatBottomSheetContainer extends BasePortalOutlet implements OnDestr
8790
private _changeDetectorRef: ChangeDetectorRef,
8891
private _focusTrapFactory: FocusTrapFactory,
8992
breakpointObserver: BreakpointObserver,
90-
@Optional() @Inject(DOCUMENT) private _document: Document) {
93+
@Optional() @Inject(DOCUMENT) document: any) {
9194
super();
9295

96+
this._document = document;
9397
this._breakpointSubscription = breakpointObserver
9498
.observe([Breakpoints.Medium, Breakpoints.Large, Breakpoints.XLarge])
9599
.subscribe(() => {

src/lib/datepicker/datepicker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export class MatDatepicker<D> implements OnDestroy, CanColor {
313313
@Inject(MAT_DATEPICKER_SCROLL_STRATEGY) private _scrollStrategy,
314314
@Optional() private _dateAdapter: DateAdapter<D>,
315315
@Optional() private _dir: Directionality,
316-
@Optional() @Inject(DOCUMENT) private _document: Document) {
316+
@Optional() @Inject(DOCUMENT) private _document: any) {
317317
if (!this._dateAdapter) {
318318
throw createMissingDateImplError('DateAdapter');
319319
}
@@ -371,7 +371,7 @@ export class MatDatepicker<D> implements OnDestroy, CanColor {
371371
throw Error('Attempted to open an MatDatepicker with no associated input.');
372372
}
373373
if (this._document) {
374-
this._focusedElementBeforeOpen = this._document.activeElement as HTMLElement;
374+
this._focusedElementBeforeOpen = this._document.activeElement;
375375
}
376376

377377
this.touchUi ? this._openAsDialog() : this._openAsPopup();

src/lib/dialog/dialog-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class MatDialogContainer extends BasePortalOutlet {
9898
private _elementRef: ElementRef,
9999
private _focusTrapFactory: FocusTrapFactory,
100100
private _changeDetectorRef: ChangeDetectorRef,
101-
@Optional() @Inject(DOCUMENT) private _document: Document) {
101+
@Optional() @Inject(DOCUMENT) private _document: any) {
102102

103103
super();
104104
}

src/lib/icon/icon-registry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class SvgIconConfig {
9494
*/
9595
@Injectable({providedIn: 'root'})
9696
export class MatIconRegistry {
97+
private _document: Document;
98+
9799
/**
98100
* URLs and cached SVG elements for individual icons. Keys are of the format "[namespace]:[icon]".
99101
*/
@@ -124,7 +126,9 @@ export class MatIconRegistry {
124126
constructor(
125127
@Optional() private _httpClient: HttpClient,
126128
private _sanitizer: DomSanitizer,
127-
@Optional() @Inject(DOCUMENT) private _document: Document) {}
129+
@Optional() @Inject(DOCUMENT) document: any) {
130+
this._document = document;
131+
}
128132

129133
/**
130134
* Registers an icon by URL in the default namespace.

src/lib/menu/menu-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class MatMenuContent implements OnDestroy {
3535
private _appRef: ApplicationRef,
3636
private _injector: Injector,
3737
private _viewContainerRef: ViewContainerRef,
38-
@Inject(DOCUMENT) private _document: Document) {}
38+
@Inject(DOCUMENT) private _document: any) {}
3939

4040
/**
4141
* Attaches the content with a particular context.

src/lib/progress-spinner/progress-spinner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
144144

145145
constructor(public _elementRef: ElementRef,
146146
platform: Platform,
147-
@Optional() @Inject(DOCUMENT) private _document: Document) {
147+
@Optional() @Inject(DOCUMENT) private _document: any) {
148148

149149
super(_elementRef);
150150
this._fallbackAnimation = platform.EDGE || platform.TRIDENT;
@@ -244,7 +244,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements
244244
})
245245
export class MatSpinner extends MatProgressSpinner {
246246
constructor(elementRef: ElementRef, platform: Platform,
247-
@Optional() @Inject(DOCUMENT) document: Document) {
247+
@Optional() @Inject(DOCUMENT) document: any) {
248248
super(elementRef, platform, document);
249249
this.mode = 'indeterminate';
250250
}

0 commit comments

Comments
 (0)