Skip to content

Commit 8c98013

Browse files
crisbetommalerba
authored andcommitted
fix(tabs): avoid template type checking errors with Ivy (#17228)
Along the same lines as #17022. Adds annotations to the various base classes that declare inputs, because the Ivy template type checker doesn't handle base defs at the moment. Fixes #17121.
1 parent 4126029 commit 8c98013

File tree

7 files changed

+57
-11
lines changed

7 files changed

+57
-11
lines changed

src/material/tabs/paginated-tab-header.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
AfterContentInit,
1818
AfterViewInit,
1919
OnDestroy,
20+
Directive,
21+
Inject,
2022
} from '@angular/core';
2123
import {Direction, Directionality} from '@angular/cdk/bidi';
2224
import {coerceNumberProperty} from '@angular/cdk/coercion';
@@ -26,6 +28,7 @@ import {END, ENTER, HOME, SPACE, hasModifierKey} from '@angular/cdk/keycodes';
2628
import {merge, of as observableOf, Subject, timer, fromEvent} from 'rxjs';
2729
import {takeUntil} from 'rxjs/operators';
2830
import {Platform, normalizePassiveListenerOptions} from '@angular/cdk/platform';
31+
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
2932

3033

3134
/** Config used to bind passive event listeners */
@@ -62,7 +65,12 @@ export type MatPaginatedTabHeaderItem = FocusableOption & {elementRef: ElementRe
6265

6366
/**
6467
* Base class for a tab header that supported pagination.
68+
* @docs-private
6569
*/
70+
@Directive({
71+
// TODO(crisbeto): this selector can be removed when we update to Angular 9.0.
72+
selector: 'do-not-use-abstract-mat-paginated-tab-header'
73+
})
6674
export abstract class MatPaginatedTabHeader implements AfterContentChecked, AfterContentInit,
6775
AfterViewInit, OnDestroy {
6876
abstract _items: QueryList<MatPaginatedTabHeaderItem>;
@@ -140,7 +148,7 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
140148
* parameters to become required.
141149
*/
142150
private _platform?: Platform,
143-
public _animationMode?: string) {
151+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
144152

145153
// Bind the `mouseleave` event on the outside since it doesn't change anything in the view.
146154
_ngZone.runOutsideAngular(() => {

src/material/tabs/public-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
export * from './tabs-module';
9+
export {MatTabsModule} from './tabs-module';
1010
export * from './tab-group';
1111
export {MatInkBar, _MatInkBarPositioner, _MAT_INK_BAR_POSITIONER} from './ink-bar';
1212
export {

src/material/tabs/tab-body.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ export class MatTabBodyPortal extends CdkPortalOutlet implements OnInit, OnDestr
9898
}
9999
}
100100

101-
/** Base class with all of the `MatTabBody` functionality. */
101+
/**
102+
* Base class with all of the `MatTabBody` functionality.
103+
* @docs-private
104+
*/
105+
@Directive({
106+
// TODO(crisbeto): this selector can be removed when we update to Angular 9.0.
107+
selector: 'do-not-use-abstract-mat-tab-body-base'
108+
})
102109
// tslint:disable-next-line:class-name
103110
export abstract class _MatTabBodyBase implements OnInit, OnDestroy {
104111
/** Current position of the tab-body in the tab-group. Zero means that the tab is visible. */

src/material/tabs/tab-group.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
Optional,
2626
Inject,
2727
InjectionToken,
28+
Directive,
2829
} from '@angular/core';
2930
import {
3031
CanColor,
@@ -76,7 +77,14 @@ interface MatTabGroupBaseHeader {
7677
focusIndex: number;
7778
}
7879

79-
/** Base class with all of the `MatTabGroupBase` functionality. */
80+
/**
81+
* Base class with all of the `MatTabGroupBase` functionality.
82+
* @docs-private
83+
*/
84+
@Directive({
85+
// TODO(crisbeto): this selector can be removed when we update to Angular 9.0.
86+
selector: 'do-not-use-abstract-mat-tab-group-base'
87+
})
8088
// tslint:disable-next-line:class-name
8189
export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements AfterContentInit,
8290
AfterContentChecked, OnDestroy, CanColor, CanDisableRipple {

src/material/tabs/tab-header.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
AfterViewInit,
2626
Input,
2727
Inject,
28+
Directive,
2829
} from '@angular/core';
2930
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
3031
import {coerceBooleanProperty} from '@angular/cdk/coercion';
@@ -33,7 +34,14 @@ import {MatTabLabelWrapper} from './tab-label-wrapper';
3334
import {Platform} from '@angular/cdk/platform';
3435
import {MatPaginatedTabHeader} from './paginated-tab-header';
3536

36-
/** Base class with all of the `MatTabHeader` functionality. */
37+
/**
38+
* Base class with all of the `MatTabHeader` functionality.
39+
* @docs-private
40+
*/
41+
@Directive({
42+
// TODO(crisbeto): this selector can be removed when we update to Angular 9.0.
43+
selector: 'do-not-use-abstract-mat-tab-header-base'
44+
})
3745
// tslint:disable-next-line:class-name
3846
export abstract class _MatTabHeaderBase extends MatPaginatedTabHeader implements
3947
AfterContentChecked, AfterContentInit, AfterViewInit, OnDestroy {

src/material/tabs/tab-nav-bar/tab-nav-bar.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ import {MatInkBar} from '../ink-bar';
4848
import {MatPaginatedTabHeader, MatPaginatedTabHeaderItem} from '../paginated-tab-header';
4949
import {startWith, takeUntil} from 'rxjs/operators';
5050

51-
/** Base class with all of the `MatTabNav` functionality. */
51+
/**
52+
* Base class with all of the `MatTabNav` functionality.
53+
* @docs-private
54+
*/
55+
@Directive({
56+
// TODO(crisbeto): this selector can be removed when we update to Angular 9.0.
57+
selector: 'do-not-use-abstract-mat-tab-nav-base'
58+
})
5259
// tslint:disable-next-line:class-name
5360
export abstract class _MatTabNavBase extends MatPaginatedTabHeader implements AfterContentChecked,
5461
AfterContentInit, OnDestroy {

src/material/tabs/tabs-module.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ import {ObserversModule} from '@angular/cdk/observers';
1010
import {PortalModule} from '@angular/cdk/portal';
1111
import {CommonModule} from '@angular/common';
1212
import {NgModule} from '@angular/core';
13+
import {A11yModule} from '@angular/cdk/a11y';
1314
import {MatCommonModule, MatRippleModule} from '@angular/material/core';
1415
import {MatInkBar} from './ink-bar';
1516
import {MatTab} from './tab';
16-
import {MatTabBody, MatTabBodyPortal} from './tab-body';
17+
import {MatTabBody, MatTabBodyPortal, _MatTabBodyBase} from './tab-body';
1718
import {MatTabContent} from './tab-content';
18-
import {MatTabGroup} from './tab-group';
19-
import {MatTabHeader} from './tab-header';
19+
import {MatTabGroup, _MatTabGroupBase} from './tab-group';
20+
import {MatTabHeader, _MatTabHeaderBase} from './tab-header';
2021
import {MatTabLabel} from './tab-label';
2122
import {MatTabLabelWrapper} from './tab-label-wrapper';
22-
import {MatTabLink, MatTabNav} from './tab-nav-bar/tab-nav-bar';
23-
import {A11yModule} from '@angular/cdk/a11y';
23+
import {MatTabLink, MatTabNav, _MatTabNavBase} from './tab-nav-bar/tab-nav-bar';
24+
import {MatPaginatedTabHeader} from './paginated-tab-header';
2425

2526

2627
@NgModule({
@@ -54,6 +55,13 @@ import {A11yModule} from '@angular/cdk/a11y';
5455
MatTabBodyPortal,
5556
MatTabHeader,
5657
MatTabContent,
58+
59+
// TODO(crisbeto): these can be removed once they're turned into selector-less directives.
60+
MatPaginatedTabHeader as any,
61+
_MatTabGroupBase as any,
62+
_MatTabNavBase as any,
63+
_MatTabBodyBase as any,
64+
_MatTabHeaderBase as any,
5765
],
5866
})
5967
export class MatTabsModule {}

0 commit comments

Comments
 (0)