Skip to content

Commit af065e8

Browse files
committed
refactor(material/tabs): fix strict property initialization errors
Updates the code to be compatible with strict property initialization.
1 parent dabbf3e commit af065e8

File tree

11 files changed

+66
-65
lines changed

11 files changed

+66
-65
lines changed

src/material/tabs/ink-bar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export class MatInkBar {
7575
@Directive()
7676
export abstract class InkBarItem implements OnInit, OnDestroy {
7777
private _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
78-
private _inkBarElement: HTMLElement | null;
79-
private _inkBarContentElement: HTMLElement | null;
78+
private _inkBarElement: HTMLElement | null = null;
79+
private _inkBarContentElement: HTMLElement | null = null;
8080
private _fitToContent = false;
8181

8282
/** Whether the ink bar should fit to the entire tab or just its content. */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ export abstract class MatPaginatedTabHeader
113113
* The number of tab labels that are displayed on the header. When this changes, the header
114114
* should re-evaluate the scroll position.
115115
*/
116-
private _tabLabelCount: number;
116+
private _tabLabelCount!: number;
117117

118118
/** Whether the scroll distance has changed and should be applied after the view is checked. */
119-
private _scrollDistanceChanged: boolean;
119+
private _scrollDistanceChanged = false;
120120

121121
/** Used to manage focus between the tabs. */
122122
protected _keyManager: FocusKeyManager<MatPaginatedTabHeaderItem> | undefined;
123123

124124
/** Cached text content of the header. */
125-
private _currentTextContent: string;
125+
private _currentTextContent!: string;
126126

127127
/** Stream that will stop the automated scrolling. */
128128
private _stopScrolling = new Subject<void>();

src/material/tabs/tab-body.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ describe('MatTabBody', () => {
139139
})
140140
class SimpleTabBodyApp implements AfterViewInit {
141141
content = signal<TemplatePortal | undefined>(undefined);
142-
position: number;
142+
position!: number;
143143

144-
@ViewChild(MatTabBody) tabBody: MatTabBody;
145-
@ViewChild(TemplateRef) template: TemplateRef<any>;
144+
@ViewChild(MatTabBody) tabBody!: MatTabBody;
145+
@ViewChild(TemplateRef) template!: TemplateRef<any>;
146146

147147
private readonly _viewContainerRef = inject(ViewContainerRef);
148148

src/material/tabs/tab-body.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ export class MatTabBody implements OnInit, OnDestroy {
141141
private _renderer = inject(Renderer2);
142142
private _diAnimationsDisabled = _animationsDisabled();
143143
private _eventCleanups?: (() => void)[];
144-
private _initialized: boolean;
145-
private _fallbackTimer: ReturnType<typeof setTimeout>;
144+
private _initialized = false;
145+
private _fallbackTimer: ReturnType<typeof setTimeout> | undefined;
146146

147147
/** Current position of the tab-body in the tab-group. Zero means that the tab is visible. */
148-
private _positionIndex: number;
148+
private _positionIndex!: number;
149149

150150
/** Subscription to the directionality change observable. */
151151
private _dirChangeSubscription = Subscription.EMPTY;
152152

153153
/** Current position of the body within the tab group. */
154-
_position: MatTabBodyPositionState;
154+
_position!: MatTabBodyPositionState;
155155

156156
/** Previous position of the body. */
157157
protected _previousPosition: MatTabBodyPositionState | undefined;
@@ -169,13 +169,13 @@ export class MatTabBody implements OnInit, OnDestroy {
169169
@Output() readonly _onCentered: EventEmitter<void> = new EventEmitter<void>(true);
170170

171171
/** The portal host inside of this container into which the tab body content will be loaded. */
172-
@ViewChild(MatTabBodyPortal) _portalHost: MatTabBodyPortal;
172+
@ViewChild(MatTabBodyPortal) _portalHost!: MatTabBodyPortal;
173173

174174
/** Element in which the content is rendered. */
175175
@ViewChild('content') _contentElement: ElementRef<HTMLElement> | undefined;
176176

177177
/** The tab body content to display. */
178-
@Input('content') _content: TemplatePortal;
178+
@Input('content') _content!: TemplatePortal;
179179

180180
// Note that the default value will always be overwritten by `MatTabBody`, but we need one
181181
// anyway to prevent the animations module from throwing an error if the body is used on its own.

src/material/tabs/tab-group.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,16 +1246,16 @@ describe('MatTabGroup labels aligned with a config', () => {
12461246
imports: [MatTabsModule],
12471247
})
12481248
class SimpleTabsTestApp {
1249-
@ViewChild(MatTabGroup) tabGroup: MatTabGroup;
1250-
@ViewChildren(MatTab) tabs: QueryList<MatTab>;
1249+
@ViewChild(MatTabGroup) tabGroup!: MatTabGroup;
1250+
@ViewChildren(MatTab) tabs!: QueryList<MatTab>;
12511251
selectedIndex: number = 1;
12521252
focusEvent: any;
12531253
selectEvent: any;
12541254
disableRipple: boolean = false;
12551255
contentTabIndex: number | null = null;
12561256
headerPosition: MatTabHeaderPosition = 'above';
1257-
ariaLabel: string;
1258-
ariaLabelledby: string;
1257+
ariaLabel!: string;
1258+
ariaLabelledby!: string;
12591259
secondTabId: string | null = null;
12601260
handleFocus(event: any) {
12611261
this.focusEvent = event;
@@ -1347,7 +1347,7 @@ class BindedTabsTestApp {
13471347
imports: [MatTabsModule],
13481348
})
13491349
class DisabledTabsTestApp {
1350-
@ViewChildren(MatTab) tabs: QueryList<MatTab>;
1350+
@ViewChildren(MatTab) tabs!: QueryList<MatTab>;
13511351
isDisabled = false;
13521352
}
13531353

@@ -1370,7 +1370,7 @@ class AsyncTabsTestApp implements OnInit {
13701370
{label: 'two', content: 'two'},
13711371
];
13721372

1373-
tabs: Observable<any>;
1373+
tabs!: Observable<any>;
13741374

13751375
ngOnInit() {
13761376
// Use ngOnInit because there is some issue with scheduling the async task in the constructor.
@@ -1414,7 +1414,7 @@ class TabGroupWithSimpleApi {
14141414
imports: [MatTabsModule],
14151415
})
14161416
class NestedTabs {
1417-
@ViewChildren(MatTabGroup) groups: QueryList<MatTabGroup>;
1417+
@ViewChildren(MatTabGroup) groups!: QueryList<MatTabGroup>;
14181418
}
14191419

14201420
@Component({
@@ -1443,8 +1443,8 @@ class TemplateTabs {}
14431443
imports: [MatTabsModule],
14441444
})
14451445
class TabGroupWithAriaInputs {
1446-
ariaLabel: string;
1447-
ariaLabelledby: string;
1446+
ariaLabel!: string;
1447+
ariaLabelledby!: string;
14481448
}
14491449

14501450
@Component({
@@ -1485,7 +1485,7 @@ class TabsWithCustomAnimationDuration {}
14851485
imports: [MatTabsModule],
14861486
})
14871487
class TabGroupWithIndirectDescendantTabs {
1488-
@ViewChild(MatTabGroup) tabGroup: MatTabGroup;
1488+
@ViewChild(MatTabGroup) tabGroup!: MatTabGroup;
14891489
}
14901490

14911491
@Component({
@@ -1520,7 +1520,7 @@ class TabGroupWithInkBarFitToContent {
15201520
imports: [MatTabsModule],
15211521
})
15221522
class TabGroupWithSpaceAbove {
1523-
@ViewChild(MatTabGroup) tabGroup: MatTabGroup;
1523+
@ViewChild(MatTabGroup) tabGroup!: MatTabGroup;
15241524
}
15251525

15261526
@Component({
@@ -1559,8 +1559,8 @@ class NestedTabGroupWithLabel {}
15591559
imports: [MatTabsModule],
15601560
})
15611561
class TabsWithClassesTestApp {
1562-
labelClassList: string | string[];
1563-
bodyClassList: string | string[];
1562+
labelClassList!: string | string[];
1563+
bodyClassList!: string | string[];
15641564
}
15651565

15661566
@Component({

src/material/tabs/tab-group.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ export class MatTabGroup
105105
* All tabs inside the tab group. This includes tabs that belong to groups that are nested
106106
* inside the current one. We filter out only the tabs that belong to this group in `_tabs`.
107107
*/
108-
@ContentChildren(MatTab, {descendants: true}) _allTabs: QueryList<MatTab>;
108+
@ContentChildren(MatTab, {descendants: true}) _allTabs!: QueryList<MatTab>;
109109
@ViewChildren(MatTabBody) _tabBodies: QueryList<MatTabBody> | undefined;
110-
@ViewChild('tabBodyWrapper') _tabBodyWrapper: ElementRef;
111-
@ViewChild('tabHeader') _tabHeader: MatTabHeader;
110+
@ViewChild('tabBodyWrapper') _tabBodyWrapper!: ElementRef;
111+
@ViewChild('tabHeader') _tabHeader!: MatTabHeader;
112112

113113
/** All of the tabs that belong to the group. */
114114
_tabs: QueryList<MatTab> = new QueryList<MatTab>();
@@ -177,7 +177,7 @@ export class MatTabGroup
177177
const stringValue = value + '';
178178
this._animationDuration = /^\d+$/.test(stringValue) ? value + 'ms' : stringValue;
179179
}
180-
private _animationDuration: string;
180+
private _animationDuration!: string;
181181

182182
/**
183183
* `tabindex` to be set on the inner element that wraps the tab content. Can be used for improved
@@ -194,7 +194,7 @@ export class MatTabGroup
194194
this._contentTabIndex = isNaN(value) ? null : value;
195195
}
196196

197-
private _contentTabIndex: number | null;
197+
private _contentTabIndex: number | null = null;
198198

199199
/**
200200
* Whether pagination should be disabled. This can be used to avoid unnecessary
@@ -246,13 +246,13 @@ export class MatTabGroup
246246
this._backgroundColor = value;
247247
}
248248

249-
private _backgroundColor: ThemePalette;
249+
private _backgroundColor!: ThemePalette;
250250

251251
/** Aria label of the inner `tablist` of the group. */
252-
@Input('aria-label') ariaLabel: string;
252+
@Input('aria-label') ariaLabel!: string;
253253

254254
/** Sets the `aria-labelledby` of the inner `tablist` of the group. */
255-
@Input('aria-labelledby') ariaLabelledby: string;
255+
@Input('aria-labelledby') ariaLabelledby!: string;
256256

257257
/** Output to enable support for two-way binding on `[(selectedIndex)]` */
258258
@Output() readonly selectedIndexChange: EventEmitter<number> = new EventEmitter<number>();
@@ -589,7 +589,7 @@ export class MatTabGroup
589589
/** A simple change event emitted on focus or selection changes. */
590590
export class MatTabChangeEvent {
591591
/** Index of the currently-selected tab. */
592-
index: number;
592+
index!: number;
593593
/** Reference to the currently-selected tab. */
594-
tab: MatTab;
594+
tab!: MatTab;
595595
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,13 +743,13 @@ interface Tab {
743743
class SimpleTabHeaderApp {
744744
disableRipple: boolean = false;
745745
selectedIndex: number = 0;
746-
focusedIndex: number;
746+
focusedIndex!: number;
747747
disabledTabIndex = 1;
748748
tabs: Tab[] = [{label: 'tab one'}, {label: 'tab one'}, {label: 'tab one'}, {label: 'tab one'}];
749749
dir: Direction = 'ltr';
750-
disablePagination: boolean;
750+
disablePagination: boolean = false;
751751

752-
@ViewChild(MatTabHeader, {static: true}) tabHeader: MatTabHeader;
752+
@ViewChild(MatTabHeader, {static: true}) tabHeader!: MatTabHeader;
753753

754754
private readonly _changeDetectorRef = inject(ChangeDetectorRef);
755755

src/material/tabs/tab-header.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ export class MatTabHeader
5252
extends MatPaginatedTabHeader
5353
implements AfterContentChecked, AfterContentInit, AfterViewInit, OnDestroy
5454
{
55-
@ContentChildren(MatTabLabelWrapper, {descendants: false}) _items: QueryList<MatTabLabelWrapper>;
56-
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
57-
@ViewChild('tabList', {static: true}) _tabList: ElementRef;
58-
@ViewChild('tabListInner', {static: true}) _tabListInner: ElementRef;
59-
@ViewChild('nextPaginator') _nextPaginator: ElementRef<HTMLElement>;
60-
@ViewChild('previousPaginator') _previousPaginator: ElementRef<HTMLElement>;
61-
_inkBar: MatInkBar;
55+
@ContentChildren(MatTabLabelWrapper, {descendants: false}) _items!: QueryList<MatTabLabelWrapper>;
56+
@ViewChild('tabListContainer', {static: true}) _tabListContainer!: ElementRef;
57+
@ViewChild('tabList', {static: true}) _tabList!: ElementRef;
58+
@ViewChild('tabListInner', {static: true}) _tabListInner!: ElementRef;
59+
@ViewChild('nextPaginator') _nextPaginator!: ElementRef<HTMLElement>;
60+
@ViewChild('previousPaginator') _previousPaginator!: ElementRef<HTMLElement>;
61+
_inkBar!: MatInkBar;
6262

6363
/** Aria label of the header. */
64-
@Input('aria-label') ariaLabel: string;
64+
@Input('aria-label') ariaLabel!: string;
6565

6666
/** Sets the `aria-labelledby` of the header. */
67-
@Input('aria-labelledby') ariaLabelledby: string;
67+
@Input('aria-labelledby') ariaLabelledby!: string;
6868

6969
/** Whether the ripple effect is disabled or not. */
7070
@Input({transform: booleanAttribute})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ describe('MatTabNavBar with enabled animations', () => {
554554
imports: [MatTabsModule],
555555
})
556556
class SimpleTabNavBarTestApp {
557-
@ViewChild(MatTabNav) tabNavBar: MatTabNav;
558-
@ViewChildren(MatTabLink) tabLinks: QueryList<MatTabLink>;
557+
@ViewChild(MatTabNav) tabNavBar!: MatTabNav;
558+
@ViewChildren(MatTabLink) tabLinks!: QueryList<MatTabLink>;
559559

560560
label = '';
561561
disabled = false;

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ export class MatTabNav extends MatPaginatedTabHeader implements AfterContentInit
9999
this._animationDuration = /^\d+$/.test(stringValue) ? value + 'ms' : stringValue;
100100
}
101101

102-
private _animationDuration: string;
102+
private _animationDuration!: string;
103103

104104
/** Query list of all tab links of the tab navigation. */
105-
@ContentChildren(forwardRef(() => MatTabLink), {descendants: true}) _items: QueryList<MatTabLink>;
105+
@ContentChildren(forwardRef(() => MatTabLink), {descendants: true})
106+
_items!: QueryList<MatTabLink>;
106107

107108
/**
108109
* Theme color of the background of the tab nav. This API is supported in M2 themes only, it
@@ -155,12 +156,12 @@ export class MatTabNav extends MatPaginatedTabHeader implements AfterContentInit
155156
*/
156157
@Input() tabPanel?: MatTabNavPanel;
157158

158-
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
159-
@ViewChild('tabList', {static: true}) _tabList: ElementRef;
160-
@ViewChild('tabListInner', {static: true}) _tabListInner: ElementRef;
161-
@ViewChild('nextPaginator') _nextPaginator: ElementRef<HTMLElement>;
162-
@ViewChild('previousPaginator') _previousPaginator: ElementRef<HTMLElement>;
163-
_inkBar: MatInkBar;
159+
@ViewChild('tabListContainer', {static: true}) _tabListContainer!: ElementRef;
160+
@ViewChild('tabList', {static: true}) _tabList!: ElementRef;
161+
@ViewChild('tabListInner', {static: true}) _tabListInner!: ElementRef;
162+
@ViewChild('nextPaginator') _nextPaginator!: ElementRef<HTMLElement>;
163+
@ViewChild('previousPaginator') _previousPaginator!: ElementRef<HTMLElement>;
164+
_inkBar!: MatInkBar;
164165

165166
constructor(...args: unknown[]);
166167

0 commit comments

Comments
 (0)