From 2f725c976000122094f6f27b05e218d350ece640 Mon Sep 17 00:00:00 2001 From: Jeremy Elbourn Date: Wed, 2 Oct 2019 09:35:11 -0700 Subject: [PATCH 1/2] fix(tabs): no longer use OnPush This resolves an issue with ivy where the template content would be checked out of sync with the tab view. See #15440 for additional context. --- src/material/tabs/tab-body.ts | 3 ++- src/material/tabs/tab-group.ts | 3 ++- src/material/tabs/tab-header.ts | 3 ++- src/material/tabs/tab-nav-bar/tab-nav-bar.ts | 3 ++- src/material/tabs/tab.ts | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/material/tabs/tab-body.ts b/src/material/tabs/tab-body.ts index 52f9734dce64..e1cf5ba8d685 100644 --- a/src/material/tabs/tab-body.ts +++ b/src/material/tabs/tab-body.ts @@ -251,7 +251,8 @@ export abstract class _MatTabBodyBase implements OnInit, OnDestroy { templateUrl: 'tab-body.html', styleUrls: ['tab-body.css'], encapsulation: ViewEncapsulation.None, - changeDetection: ChangeDetectionStrategy.OnPush, + // tslint:disable-next-line:validate-decorators + changeDetection: ChangeDetectionStrategy.Default, animations: [matTabsAnimations.translateTab], host: { 'class': 'mat-tab-body', diff --git a/src/material/tabs/tab-group.ts b/src/material/tabs/tab-group.ts index 72ca3d972df1..e7c103f1f667 100644 --- a/src/material/tabs/tab-group.ts +++ b/src/material/tabs/tab-group.ts @@ -360,7 +360,8 @@ export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements templateUrl: 'tab-group.html', styleUrls: ['tab-group.css'], encapsulation: ViewEncapsulation.None, - changeDetection: ChangeDetectionStrategy.OnPush, + // tslint:disable-next-line:validate-decorators + changeDetection: ChangeDetectionStrategy.Default, inputs: ['color', 'disableRipple'], host: { 'class': 'mat-tab-group', diff --git a/src/material/tabs/tab-header.ts b/src/material/tabs/tab-header.ts index 464913d1eab3..61c3c5601c5b 100644 --- a/src/material/tabs/tab-header.ts +++ b/src/material/tabs/tab-header.ts @@ -83,7 +83,8 @@ export abstract class _MatTabHeaderBase extends MatPaginatedTabHeader implements inputs: ['selectedIndex'], outputs: ['selectFocusedIndex', 'indexFocused'], encapsulation: ViewEncapsulation.None, - changeDetection: ChangeDetectionStrategy.OnPush, + // tslint:disable-next-line:validate-decorators + changeDetection: ChangeDetectionStrategy.Default, host: { 'class': 'mat-tab-header', '[class.mat-tab-header-pagination-controls-enabled]': '_showPaginationControls', diff --git a/src/material/tabs/tab-nav-bar/tab-nav-bar.ts b/src/material/tabs/tab-nav-bar/tab-nav-bar.ts index fe64f3b02a50..4780f6f24f63 100644 --- a/src/material/tabs/tab-nav-bar/tab-nav-bar.ts +++ b/src/material/tabs/tab-nav-bar/tab-nav-bar.ts @@ -160,7 +160,8 @@ export abstract class _MatTabNavBase extends MatPaginatedTabHeader implements Af '[class.mat-warn]': 'color === "warn"', }, encapsulation: ViewEncapsulation.None, - changeDetection: ChangeDetectionStrategy.OnPush, + // tslint:disable-next-line:validate-decorators + changeDetection: ChangeDetectionStrategy.Default, }) export class MatTabNav extends _MatTabNavBase { @ContentChildren(forwardRef(() => MatTabLink), {descendants: true}) _items: QueryList; diff --git a/src/material/tabs/tab.ts b/src/material/tabs/tab.ts index 3f84dfff04c5..d67cba1bafc5 100644 --- a/src/material/tabs/tab.ts +++ b/src/material/tabs/tab.ts @@ -38,7 +38,8 @@ const _MatTabMixinBase: CanDisableCtor & typeof MatTabBase = selector: 'mat-tab', templateUrl: 'tab.html', inputs: ['disabled'], - changeDetection: ChangeDetectionStrategy.OnPush, + // tslint:disable-next-line:validate-decorators + changeDetection: ChangeDetectionStrategy.Default, encapsulation: ViewEncapsulation.None, exportAs: 'matTab', }) From 27395aefd6a8b8d12e7bc3a6dcd15b1a687c2031 Mon Sep 17 00:00:00 2001 From: Jeremy Elbourn Date: Thu, 10 Oct 2019 14:56:02 -0700 Subject: [PATCH 2/2] workaround for gcp issue --- src/material/tabs/tab.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/material/tabs/tab.ts b/src/material/tabs/tab.ts index d67cba1bafc5..066fe921c995 100644 --- a/src/material/tabs/tab.ts +++ b/src/material/tabs/tab.ts @@ -45,7 +45,18 @@ const _MatTabMixinBase: CanDisableCtor & typeof MatTabBase = }) export class MatTab extends _MatTabMixinBase implements OnInit, CanDisable, OnChanges, OnDestroy { /** Content for the tab label given by ``. */ - @ContentChild(MatTabLabel, {static: false}) templateLabel: MatTabLabel; + @ContentChild(MatTabLabel, {static: false}) + get templateLabel(): MatTabLabel { return this._templateLabel; } + set templateLabel(value: MatTabLabel) { + // Only update the templateLabel via query if there is actually + // a MatTabLabel found. This works around an issue where a user may have + // manually set `templateLabel` during creation mode, which would then get clobbered + // by `undefined` when this query resolves. + if (value) { + this._templateLabel = value; + } + } + private _templateLabel: MatTabLabel; /** * Template provided in the tab content that will be used if present, used to enable lazy-loading