Skip to content

Commit 6531d44

Browse files
committed
refactor: constructor breaking changes for 8.0
Goes through the constructor-related breaking changes for 8.0 in all of the CDK symbols plus `material/form-field` and `material/tabs`. BREAKING CHANGES: * `CdkDrag`: `viewportRuler` and `dragDropRegistry` parameters have been removed from the constructor. Furthermore the `dragDrop` and `_changeDetectorRef` parameters in are now required. * `CdkDropList`: `dragDropRegistry` and `_documents` parameters have been removed, and `dragDrop` parameter is now required. * `ConnectedPositionStrategy`: `platform` parameter is now required and a new `overlayContainer` parameter has been added. * `FlexibleConnectedPositionStrategy`: `_platform` and `_overlayContainer` parameters are now required. * `OverlayPositionBuilder`: `_platform` and `_overlayContainer` parameters are now required. * `CdkStepper`: `_elementRef` and `_document` parameters are now required. * `CdkTable`: `_document` and `_platform` parameters are now required. * `MatFormField`: `_platform`, `_ngZone` and `_animationMode` parameters are now required. * `MatTabLink`: `_focusMonitor` parameter is now required. * `MatVerticalStepper`: `_elementRef` and `_document` parameters are now required.
1 parent 823d471 commit 6531d44

File tree

17 files changed

+88
-211
lines changed

17 files changed

+88
-211
lines changed

src/cdk/drag-drop/directives/drag.ts

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {Directionality} from '@angular/cdk/bidi';
10-
import {ViewportRuler} from '@angular/cdk/scrolling';
1110
import {DOCUMENT} from '@angular/common';
1211
import {
1312
AfterViewInit,
@@ -33,7 +32,6 @@ import {
3332
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';
3433
import {Observable, Observer, Subject, merge} from 'rxjs';
3534
import {startWith, take, map, takeUntil, switchMap, tap} from 'rxjs/operators';
36-
import {DragDropRegistry} from '../drag-drop-registry';
3735
import {
3836
CdkDragDrop,
3937
CdkDragEnd,
@@ -49,7 +47,6 @@ import {CdkDragPreview} from './drag-preview';
4947
import {CDK_DROP_LIST} from '../drop-list-container';
5048
import {CDK_DRAG_PARENT} from '../drag-parent';
5149
import {DragRef, DragRefConfig, Point} from '../drag-ref';
52-
import {DropListRef} from '../drop-list-ref';
5350
import {CdkDropListInternal as CdkDropList} from './drop-list';
5451
import {DragDrop} from '../drag-drop';
5552

@@ -176,36 +173,15 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
176173
});
177174

178175
constructor(
179-
/** Element that the draggable is attached to. */
180-
public element: ElementRef<HTMLElement>,
181-
/** Droppable container that the draggable is a part of. */
182-
@Inject(CDK_DROP_LIST) @Optional() @SkipSelf()
183-
public dropContainer: CdkDropList,
184-
@Inject(DOCUMENT) private _document: any,
185-
private _ngZone: NgZone,
186-
private _viewContainerRef: ViewContainerRef,
187-
viewportRuler: ViewportRuler,
188-
dragDropRegistry: DragDropRegistry<DragRef, DropListRef>,
189-
@Inject(CDK_DRAG_CONFIG) config: DragRefConfig,
190-
@Optional() private _dir: Directionality,
191-
192-
/**
193-
* @deprecated `viewportRuler`, `dragDropRegistry` and `_changeDetectorRef` parameters
194-
* to be removed. Also `dragDrop` parameter to be made required.
195-
* @breaking-change 8.0.0.
196-
*/
197-
dragDrop?: DragDrop,
198-
private _changeDetectorRef?: ChangeDetectorRef) {
199-
200-
201-
// @breaking-change 8.0.0 Remove null check once the paramter is made required.
202-
if (dragDrop) {
203-
this._dragRef = dragDrop.createDrag(element, config);
204-
} else {
205-
this._dragRef = new DragRef(element, config, _document, _ngZone, viewportRuler,
206-
dragDropRegistry);
207-
}
208-
176+
/** Element that the draggable is attached to. */
177+
public element: ElementRef<HTMLElement>,
178+
/** Droppable container that the draggable is a part of. */
179+
@Inject(CDK_DROP_LIST) @Optional() @SkipSelf() public dropContainer: CdkDropList,
180+
@Inject(DOCUMENT) private _document: any, private _ngZone: NgZone,
181+
private _viewContainerRef: ViewContainerRef, @Inject(CDK_DRAG_CONFIG) config: DragRefConfig,
182+
@Optional() private _dir: Directionality, dragDrop: DragDrop,
183+
private _changeDetectorRef: ChangeDetectorRef) {
184+
this._dragRef = dragDrop.createDrag(element, config);
209185
this._dragRef.data = this;
210186
this._syncInputs(this._dragRef);
211187
this._handleEvents(this._dragRef);
@@ -338,10 +314,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
338314

339315
// Since all of these events run outside of change detection,
340316
// we need to ensure that everything is marked correctly.
341-
if (this._changeDetectorRef) {
342-
// @breaking-change 8.0.0 Remove null check for _changeDetectorRef
343-
this._changeDetectorRef.markForCheck();
344-
}
317+
this._changeDetectorRef.markForCheck();
345318
});
346319

347320
ref.released.subscribe(() => {
@@ -353,10 +326,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
353326

354327
// Since all of these events run outside of change detection,
355328
// we need to ensure that everything is marked correctly.
356-
if (this._changeDetectorRef) {
357-
// @breaking-change 8.0.0 Remove null check for _changeDetectorRef
358-
this._changeDetectorRef.markForCheck();
359-
}
329+
this._changeDetectorRef.markForCheck();
360330
});
361331

362332
ref.entered.subscribe(event => {

src/cdk/drag-drop/directives/drop-list.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ import {
2020
Directive,
2121
ChangeDetectorRef,
2222
SkipSelf,
23-
Inject,
2423
AfterContentInit,
2524
} from '@angular/core';
26-
import {DOCUMENT} from '@angular/common';
2725
import {Directionality} from '@angular/cdk/bidi';
2826
import {CdkDrag} from './drag';
29-
import {DragDropRegistry} from '../drag-drop-registry';
3027
import {CdkDragDrop, CdkDragEnter, CdkDragExit, CdkDragSortEvent} from '../drag-events';
3128
import {CDK_DROP_LIST_CONTAINER, CdkDropListContainer} from '../drop-list-container';
3229
import {CdkDropListGroup} from './drop-list-group';
@@ -154,28 +151,11 @@ export class CdkDropList<T = any> implements CdkDropListContainer, AfterContentI
154151
sorted: EventEmitter<CdkDragSortEvent<T>> = new EventEmitter<CdkDragSortEvent<T>>();
155152

156153
constructor(
157-
/** Element that the drop list is attached to. */
158-
public element: ElementRef<HTMLElement>,
159-
dragDropRegistry: DragDropRegistry<DragRef, DropListRef>,
160-
private _changeDetectorRef: ChangeDetectorRef,
161-
@Optional() private _dir?: Directionality,
162-
@Optional() @SkipSelf() private _group?: CdkDropListGroup<CdkDropList>,
163-
@Optional() @Inject(DOCUMENT) _document?: any,
164-
165-
/**
166-
* @deprecated `dragDropRegistry` and `_document` parameters to be removed.
167-
* Also `dragDrop` parameter to be made required.
168-
* @breaking-change 8.0.0.
169-
*/
170-
dragDrop?: DragDrop) {
171-
172-
// @breaking-change 8.0.0 Remove null check once `dragDrop` parameter is made required.
173-
if (dragDrop) {
174-
this._dropListRef = dragDrop.createDropList(element);
175-
} else {
176-
this._dropListRef = new DropListRef(element, dragDropRegistry, _document || document);
177-
}
178-
154+
/** Element that the drop list is attached to. */
155+
public element: ElementRef<HTMLElement>, dragDrop: DragDrop,
156+
private _changeDetectorRef: ChangeDetectorRef, @Optional() private _dir?: Directionality,
157+
@Optional() @SkipSelf() private _group?: CdkDropListGroup<CdkDropList>) {
158+
this._dropListRef = dragDrop.createDropList(element);
179159
this._dropListRef.data = this;
180160
this._dropListRef.enterPredicate = (drag: DragRef<CdkDrag>, drop: DropListRef<CdkDropList>) => {
181161
return this.enterPredicate(drag.data, drop.data);

src/cdk/overlay/position/connected-position-strategy.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
*/
88

99
import {Direction} from '@angular/cdk/bidi';
10+
import {Platform} from '@angular/cdk/platform';
1011
import {CdkScrollable, ViewportRuler} from '@angular/cdk/scrolling';
1112
import {ElementRef} from '@angular/core';
1213
import {Observable} from 'rxjs';
14+
15+
import {OverlayContainer} from '../overlay-container';
16+
import {OverlayReference} from '../overlay-reference';
17+
1318
import {
1419
ConnectedOverlayPositionChange,
1520
ConnectionPositionPair,
@@ -18,8 +23,6 @@ import {
1823
} from './connected-position';
1924
import {FlexibleConnectedPositionStrategy} from './flexible-connected-position-strategy';
2025
import {PositionStrategy} from './position-strategy';
21-
import {Platform} from '@angular/cdk/platform';
22-
import {OverlayReference} from '../overlay-reference';
2326

2427
/**
2528
* A strategy for positioning overlays. Using this strategy, an overlay is given an
@@ -56,23 +59,18 @@ export class ConnectedPositionStrategy implements PositionStrategy {
5659
}
5760

5861
constructor(
59-
originPos: OriginConnectionPosition,
60-
overlayPos: OverlayConnectionPosition,
61-
connectedTo: ElementRef<HTMLElement>,
62-
viewportRuler: ViewportRuler,
63-
document: Document,
64-
// @breaking-change 8.0.0 `platform` parameter to be made required.
65-
platform?: Platform) {
66-
62+
originPos: OriginConnectionPosition, overlayPos: OverlayConnectionPosition,
63+
connectedTo: ElementRef<HTMLElement>, viewportRuler: ViewportRuler, document: Document,
64+
platform: Platform, overlayContainer: OverlayContainer) {
6765
// Since the `ConnectedPositionStrategy` is deprecated and we don't want to maintain
6866
// the extra logic, we create an instance of the positioning strategy that has some
6967
// defaults that make it behave as the old position strategy and to which we'll
7068
// proxy all of the API calls.
71-
this._positionStrategy =
72-
new FlexibleConnectedPositionStrategy(connectedTo, viewportRuler, document, platform)
73-
.withFlexibleDimensions(false)
74-
.withPush(false)
75-
.withViewportMargin(0);
69+
this._positionStrategy = new FlexibleConnectedPositionStrategy(
70+
connectedTo, viewportRuler, document, platform, overlayContainer)
71+
.withFlexibleDimensions(false)
72+
.withPush(false)
73+
.withViewportMargin(0);
7674

7775
this.withFallbackPosition(originPos, overlayPos);
7876
}

src/cdk/overlay/position/flexible-connected-position-strategy.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,9 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
142142
}
143143

144144
constructor(
145-
connectedTo: FlexibleConnectedPositionStrategyOrigin,
146-
private _viewportRuler: ViewportRuler,
147-
private _document: Document,
148-
// @breaking-change 8.0.0 `_platform` and `_overlayContainer` parameters to be made required.
149-
private _platform?: Platform,
150-
private _overlayContainer?: OverlayContainer) {
145+
connectedTo: FlexibleConnectedPositionStrategyOrigin, private _viewportRuler: ViewportRuler,
146+
private _document: Document, private _platform: Platform,
147+
private _overlayContainer: OverlayContainer) {
151148
this.setOrigin(connectedTo);
152149
}
153150

@@ -193,8 +190,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
193190
*/
194191
apply(): void {
195192
// We shouldn't do anything if the strategy was disposed or we're on the server.
196-
// @breaking-change 8.0.0 Remove `_platform` null check once it's guaranteed to be defined.
197-
if (this._isDisposed || (this._platform && !this._platform.isBrowser)) {
193+
if (this._isDisposed || !this._platform.isBrowser) {
198194
return;
199195
}
200196

@@ -926,11 +922,8 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
926922
overlayPoint = this._pushOverlayOnScreen(overlayPoint, this._overlayRect, scrollPosition);
927923
}
928924

929-
// @breaking-change 8.0.0 Currently the `_overlayContainer` is optional in order to avoid a
930-
// breaking change. The null check here can be removed once the `_overlayContainer` becomes
931-
// a required parameter.
932-
let virtualKeyboardOffset = this._overlayContainer ?
933-
this._overlayContainer.getContainerElement().getBoundingClientRect().top : 0;
925+
let virtualKeyboardOffset =
926+
this._overlayContainer.getContainerElement().getBoundingClientRect().top;
934927

935928
// Normally this would be zero, however when the overlay is attached to an input (e.g. in an
936929
// autocomplete), mobile browsers will shift everything in order to put the input in the middle

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,28 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {Platform} from '@angular/cdk/platform';
910
import {ViewportRuler} from '@angular/cdk/scrolling';
1011
import {DOCUMENT} from '@angular/common';
11-
import {ElementRef, Inject, Injectable, Optional} from '@angular/core';
12+
import {ElementRef, Inject, Injectable} from '@angular/core';
13+
14+
import {OverlayContainer} from '../overlay-container';
15+
1216
import {OriginConnectionPosition, OverlayConnectionPosition} from './connected-position';
1317
import {ConnectedPositionStrategy} from './connected-position-strategy';
1418
import {
1519
FlexibleConnectedPositionStrategy,
1620
FlexibleConnectedPositionStrategyOrigin,
1721
} from './flexible-connected-position-strategy';
1822
import {GlobalPositionStrategy} from './global-position-strategy';
19-
import {Platform} from '@angular/cdk/platform';
20-
import {OverlayContainer} from '../overlay-container';
2123

2224

2325
/** Builder for overlay position strategy. */
2426
@Injectable({providedIn: 'root'})
2527
export class OverlayPositionBuilder {
2628
constructor(
27-
private _viewportRuler: ViewportRuler,
28-
@Inject(DOCUMENT) private _document: any,
29-
// @breaking-change 8.0.0 `_platform` and `_overlayContainer` parameters to be made required.
30-
@Optional() private _platform?: Platform,
31-
@Optional() private _overlayContainer?: OverlayContainer) { }
29+
private _viewportRuler: ViewportRuler, @Inject(DOCUMENT) private _document: any,
30+
private _platform: Platform, private _overlayContainer: OverlayContainer) {}
3231

3332
/**
3433
* Creates a global position strategy.
@@ -49,9 +48,9 @@ export class OverlayPositionBuilder {
4948
elementRef: ElementRef,
5049
originPos: OriginConnectionPosition,
5150
overlayPos: OverlayConnectionPosition): ConnectedPositionStrategy {
52-
53-
return new ConnectedPositionStrategy(originPos, overlayPos, elementRef, this._viewportRuler,
54-
this._document);
51+
return new ConnectedPositionStrategy(
52+
originPos, overlayPos, elementRef, this._viewportRuler, this._document, this._platform,
53+
this._overlayContainer);
5554
}
5655

5756
/**

src/cdk/stepper/stepper.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ export class CdkStep implements OnChanges {
191191
return this.stepControl && this.stepControl.invalid && this.interacted;
192192
}
193193

194-
/** @breaking-change 8.0.0 remove the `?` after `stepperOptions` */
195194
constructor(
196195
@Inject(forwardRef(() => CdkStepper)) private _stepper: CdkStepper,
197196
@Optional() @Inject(STEPPER_GLOBAL_OPTIONS) stepperOptions?: StepperOptions) {
@@ -239,12 +238,7 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
239238

240239
/** Used for managing keyboard focus. */
241240
private _keyManager: FocusKeyManager<FocusableOption>;
242-
243-
/**
244-
* @breaking-change 8.0.0 Remove `| undefined` once the `_document`
245-
* constructor param is required.
246-
*/
247-
private _document: Document | undefined;
241+
private _document: Document;
248242

249243
/**
250244
* The list of step components that the stepper is holding.
@@ -314,11 +308,8 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
314308
protected _orientation: StepperOrientation = 'horizontal';
315309

316310
constructor(
317-
@Optional() private _dir: Directionality,
318-
private _changeDetectorRef: ChangeDetectorRef,
319-
// @breaking-change 8.0.0 `_elementRef` and `_document` parameters to become required.
320-
private _elementRef?: ElementRef<HTMLElement>,
321-
@Inject(DOCUMENT) _document?: any) {
311+
@Optional() private _dir: Directionality, private _changeDetectorRef: ChangeDetectorRef,
312+
private _elementRef: ElementRef<HTMLElement>, @Inject(DOCUMENT) _document: any) {
322313
this._groupId = nextId++;
323314
this._document = _document;
324315
}
@@ -502,10 +493,6 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
502493

503494
/** Checks whether the stepper contains the focused element. */
504495
private _containsFocus(): boolean {
505-
if (!this._document || !this._elementRef) {
506-
return false;
507-
}
508-
509496
const stepperElement = this._elementRef.nativeElement;
510497
const focusedElement = this._document.activeElement;
511498
return stepperElement === focusedElement || stepperElement.contains(focusedElement);

src/cdk/table/table.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,8 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
385385
protected readonly _differs: IterableDiffers,
386386
protected readonly _changeDetectorRef: ChangeDetectorRef,
387387
protected readonly _elementRef: ElementRef, @Attribute('role') role: string,
388-
@Optional() protected readonly _dir: Directionality,
389-
/**
390-
* @deprecated
391-
* @breaking-change 8.0.0 `_document` and `_platform` to
392-
* be made into a required parameters.
393-
*/
394-
@Inject(DOCUMENT) _document?: any, private _platform?: Platform) {
388+
@Optional() protected readonly _dir: Directionality, @Inject(DOCUMENT) _document: any,
389+
private _platform: Platform) {
395390
if (!role) {
396391
this._elementRef.nativeElement.setAttribute('role', 'grid');
397392
}
@@ -1000,17 +995,15 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
1000995

1001996
/** Adds native table sections (e.g. tbody) and moves the row outlets into them. */
1002997
private _applyNativeTableSections() {
1003-
// @breaking-change 8.0.0 remove the `|| document` once the `_document` is a required param.
1004-
const documentRef = this._document || document;
1005-
const documentFragment = documentRef.createDocumentFragment();
998+
const documentFragment = this._document.createDocumentFragment();
1006999
const sections = [
10071000
{tag: 'thead', outlet: this._headerRowOutlet},
10081001
{tag: 'tbody', outlet: this._rowOutlet},
10091002
{tag: 'tfoot', outlet: this._footerRowOutlet},
10101003
];
10111004

10121005
for (const section of sections) {
1013-
const element = documentRef.createElement(section.tag);
1006+
const element = this._document.createElement(section.tag);
10141007
element.setAttribute('role', 'rowgroup');
10151008
element.appendChild(section.outlet.elementRef.nativeElement);
10161009
documentFragment.appendChild(element);
@@ -1067,9 +1060,7 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
10671060
private _setupStickyStyler() {
10681061
const direction: Direction = this._dir ? this._dir.value : 'ltr';
10691062
this._stickyStyler = new StickyStyler(
1070-
this._isNativeHtmlTable,
1071-
// @breaking-change 8.0.0 remove the null check for `this._platform`.
1072-
this.stickyCssClass, direction, this._platform ? this._platform.isBrowser : true);
1063+
this._isNativeHtmlTable, this.stickyCssClass, direction, this._platform.isBrowser);
10731064
(this._dir ? this._dir.change : observableOf<Direction>())
10741065
.pipe(takeUntil(this._onDestroy))
10751066
.subscribe(value => {

0 commit comments

Comments
 (0)