Skip to content

Commit 309d564

Browse files
crisbetoandrewseguin
authored andcommitted
refactor(tabs): constructor breaking changes for 8.0 (#15738)
Handles the constructor-related breaking changes for 8.0. BREAKING CHANGES: * `_ngZone` and `_platform` parameters in `MatTabHeader` constructor are now required. * `changeDetectorRef` parameter in `MatTabBody` constructor is now required.
1 parent d071775 commit 309d564

File tree

4 files changed

+20
-33
lines changed

4 files changed

+20
-33
lines changed

src/lib/schematics/ng-update/data/constructor-checks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
3838
{
3939
pr: 'https://github.com/angular/material2/pull/15722',
4040
changes: ['MatExpansionPanel']
41+
},
42+
{
43+
pr: 'https://github.com/angular/material2/pull/15737',
44+
changes: ['MatTabHeader', 'MatTabBody']
4145
}
4246
],
4347

src/lib/tabs/tab-body.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,10 @@ export class MatTabBody implements OnInit, OnDestroy {
163163

164164
constructor(private _elementRef: ElementRef<HTMLElement>,
165165
@Optional() private _dir: Directionality,
166-
/**
167-
* @breaking-change 8.0.0 changeDetectorRef to be made required.
168-
*/
169-
changeDetectorRef?: ChangeDetectorRef) {
166+
changeDetectorRef: ChangeDetectorRef) {
170167

171-
if (this._dir && changeDetectorRef) {
172-
this._dirChangeSubscription = this._dir.change.subscribe((dir: Direction) => {
168+
if (_dir) {
169+
this._dirChangeSubscription = _dir.change.subscribe((dir: Direction) => {
173170
this._computePositionAnimationState(dir);
174171
changeDetectorRef.markForCheck();
175172
});

src/lib/tabs/tab-header.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,18 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
164164
private _changeDetectorRef: ChangeDetectorRef,
165165
private _viewportRuler: ViewportRuler,
166166
@Optional() private _dir: Directionality,
167-
// @breaking-change 8.0.0 `_ngZone` and `_platforms` parameters to be made required.
168-
private _ngZone?: NgZone,
169-
private _platform?: Platform) {
167+
private _ngZone: NgZone,
168+
private _platform: Platform) {
170169
super();
171170

172-
const element = _elementRef.nativeElement;
173-
const bindEvent = () => {
174-
fromEvent(element, 'mouseleave')
171+
// Bind the `mouseleave` event on the outside since it doesn't change anything in the view.
172+
_ngZone.runOutsideAngular(() => {
173+
fromEvent(_elementRef.nativeElement, 'mouseleave')
175174
.pipe(takeUntil(this._destroyed))
176175
.subscribe(() => {
177176
this._stopInterval();
178177
});
179-
};
180-
181-
// @breaking-change 8.0.0 remove null check once _ngZone is made into a required parameter.
182-
if (_ngZone) {
183-
// Bind the `mouseleave` event on the outside since it doesn't change anything in the view.
184-
_ngZone.runOutsideAngular(bindEvent);
185-
} else {
186-
bindEvent();
187-
}
178+
});
188179
}
189180

190181
ngAfterContentChecked(): void {
@@ -310,16 +301,13 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
310301
if (textContent !== this._currentTextContent) {
311302
this._currentTextContent = textContent;
312303

313-
const zoneCallback = () => {
304+
// The content observer runs outside the `NgZone` by default, which
305+
// means that we need to bring the callback back in ourselves.
306+
this._ngZone.run(() => {
314307
this.updatePagination();
315308
this._alignInkBarToSelectedTab();
316309
this._changeDetectorRef.markForCheck();
317-
};
318-
319-
// The content observer runs outside the `NgZone` by default, which
320-
// means that we need to bring the callback back in ourselves.
321-
// @breaking-change 8.0.0 Remove null check for `_ngZone` once it's a required parameter.
322-
this._ngZone ? this._ngZone.run(zoneCallback) : zoneCallback();
310+
});
323311
}
324312
}
325313

@@ -410,8 +398,7 @@ export class MatTabHeader extends _MatTabHeaderMixinBase
410398
// position to be thrown off in some cases. We have to reset it ourselves to ensure that
411399
// it doesn't get thrown off. Note that we scope it only to IE and Edge, because messing
412400
// with the scroll position throws off Chrome 71+ in RTL mode (see #14689).
413-
// @breaking-change 8.0.0 Remove null check for `platform`.
414-
if (platform && (platform.TRIDENT || platform.EDGE)) {
401+
if (platform.TRIDENT || platform.EDGE) {
415402
this._tabListContainer.nativeElement.scrollLeft = 0;
416403
}
417404
}

tools/public_api_guard/lib/tabs.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ export declare class MatTabBody implements OnInit, OnDestroy {
4848
animationDuration: string;
4949
origin: number;
5050
position: number;
51-
constructor(_elementRef: ElementRef<HTMLElement>, _dir: Directionality,
52-
changeDetectorRef?: ChangeDetectorRef);
51+
constructor(_elementRef: ElementRef<HTMLElement>, _dir: Directionality, changeDetectorRef: ChangeDetectorRef);
5352
_getLayoutDirection(): Direction;
5453
_isCenterPosition(position: MatTabBodyPositionState | string): boolean;
5554
_onTranslateTabStarted(event: AnimationEvent): void;
@@ -124,7 +123,7 @@ export declare class MatTabHeader extends _MatTabHeaderMixinBase implements Afte
124123
scrollDistance: number;
125124
readonly selectFocusedIndex: EventEmitter<number>;
126125
selectedIndex: number;
127-
constructor(_elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, _viewportRuler: ViewportRuler, _dir: Directionality, _ngZone?: NgZone | undefined, _platform?: Platform | undefined);
126+
constructor(_elementRef: ElementRef, _changeDetectorRef: ChangeDetectorRef, _viewportRuler: ViewportRuler, _dir: Directionality, _ngZone: NgZone, _platform: Platform);
128127
_alignInkBarToSelectedTab(): void;
129128
_checkPaginationEnabled(): void;
130129
_checkScrollingControls(): void;

0 commit comments

Comments
 (0)