Skip to content

Commit 8022331

Browse files
committed
refactor(material/tabs): fix circular dependencies
1 parent 66facec commit 8022331

File tree

6 files changed

+39
-22
lines changed

6 files changed

+39
-22
lines changed

src/material/tabs/public-api.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ export {
1616
} from './tab-body';
1717
export {MatTabsConfig, MAT_TABS_CONFIG} from './tab-config';
1818
export {MatTabContent, MAT_TAB_CONTENT} from './tab-content';
19-
export {MatTabLabel, MAT_TAB, MAT_TAB_LABEL} from './tab-label';
20-
export {MatTab, MAT_TAB_GROUP} from './tab';
19+
export {MatTabLabel, MAT_TAB_LABEL} from './tab-label';
20+
export {MatTab} from './tab';
21+
export {MAT_TAB, MatTabBase} from './tab-token';
22+
export {MAT_TAB_GROUP, MatTabGroupBase} from './tab-group-token';
2123
export {
2224
MatInkBar,
2325
_MatInkBarPositioner,

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

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {InjectionToken} from '@angular/core';
2+
3+
/**
4+
* Used to provide a tab group without causing a circular dependency.
5+
* @docs-private
6+
*/
7+
export interface MatTabGroupBase {}
8+
9+
/**
10+
* Used to provide a tab group without causing a circular dependency.
11+
* @docs-private
12+
*/
13+
export const MAT_TAB_GROUP = new InjectionToken<MatTabGroupBase>('MAT_TAB_GROUP');

src/material/tabs/tab-group.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
AfterViewInit,
2929
NgZone,
3030
} from '@angular/core';
31-
import {MAT_TAB_GROUP, MatTab} from './tab';
31+
import {MatTab} from './tab';
3232
import {MatTabHeader} from './tab-header';
3333
import {ThemePalette, MatRipple, _animationsDisabled} from '../core';
3434
import {merge, Subscription} from 'rxjs';
@@ -39,6 +39,7 @@ import {MatTabBody} from './tab-body';
3939
import {CdkPortalOutlet} from '@angular/cdk/portal';
4040
import {MatTabLabelWrapper} from './tab-label-wrapper';
4141
import {Platform} from '@angular/cdk/platform';
42+
import {MAT_TAB_GROUP} from './tab-group-token';
4243

4344
/** @docs-private */
4445
export interface MatTabGroupBaseHeader {

src/material/tabs/tab-label.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {Directive, InjectionToken, inject} from '@angular/core';
1010
import {CdkPortal} from '@angular/cdk/portal';
11-
import {type MatTab} from './tab';
11+
import {MAT_TAB} from './tab-token';
1212

1313
/**
1414
* Injection token that can be used to reference instances of `MatTabLabel`. It serves as
@@ -17,12 +17,6 @@ import {type MatTab} from './tab';
1717
*/
1818
export const MAT_TAB_LABEL = new InjectionToken<MatTabLabel>('MatTabLabel');
1919

20-
/**
21-
* Used to provide a tab label to a tab without causing a circular dependency.
22-
* @docs-private
23-
*/
24-
export const MAT_TAB = new InjectionToken<MatTab>('MAT_TAB');
25-
2620
/** Used to flag tab labels for use with the portal directive */
2721
@Directive({
2822
selector: '[mat-tab-label], [matTabLabel]',

src/material/tabs/tab-token.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {InjectionToken} from '@angular/core';
2+
3+
/**
4+
* Used to provide a tab without causing a circular dependency.
5+
* @docs-private
6+
*/
7+
export interface MatTabBase {}
8+
9+
/**
10+
* Used to provide a tab without causing a circular dependency.
11+
* @docs-private
12+
*/
13+
export const MAT_TAB = new InjectionToken<MatTabBase>('MAT_TAB');

src/material/tabs/tab.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@ import {
2424
inject,
2525
} from '@angular/core';
2626
import {MatTabContent} from './tab-content';
27-
import {MAT_TAB, MatTabLabel} from './tab-label';
27+
import {MatTabLabel} from './tab-label';
2828
import {TemplatePortal} from '@angular/cdk/portal';
2929
import {Subject} from 'rxjs';
3030
import {_CdkPrivateStyleLoader} from '@angular/cdk/private';
3131
import {_StructuralStylesLoader} from '../core';
32-
import {type MatTabGroup} from './tab-group';
33-
34-
/**
35-
* Used to provide a tab group to a tab without causing a circular dependency.
36-
* @docs-private
37-
*/
38-
export const MAT_TAB_GROUP = new InjectionToken<MatTabGroup>('MAT_TAB_GROUP');
32+
import {MAT_TAB, MatTabBase} from './tab-token';
33+
import {MAT_TAB_GROUP} from './tab-group-token';
3934

4035
@Component({
4136
selector: 'mat-tab',
@@ -54,7 +49,7 @@ export const MAT_TAB_GROUP = new InjectionToken<MatTabGroup>('MAT_TAB_GROUP');
5449
'hidden': '',
5550
},
5651
})
57-
export class MatTab implements OnInit, OnChanges, OnDestroy {
52+
export class MatTab implements MatTabBase, OnInit, OnChanges, OnDestroy {
5853
private _viewContainerRef = inject(ViewContainerRef);
5954
_closestTabGroup = inject(MAT_TAB_GROUP, {optional: true});
6055

@@ -76,11 +71,10 @@ export class MatTab implements OnInit, OnChanges, OnDestroy {
7671
* Template provided in the tab content that will be used if present, used to enable lazy-loading
7772
*/
7873
@ContentChild(MatTabContent, {read: TemplateRef, static: true})
79-
// The value will be set in `ngAfterViewInit`.
8074
private _explicitContent?: TemplateRef<unknown>;
8175

8276
/** Template inside the MatTab view that contains an `<ng-content>`. */
83-
@ViewChild(TemplateRef, {static: true}) _implicitContent: TemplateRef<unknown>;
77+
@ViewChild(TemplateRef, {static: true}) _implicitContent?: TemplateRef<unknown>;
8478

8579
/** Plain text label for the tab, used when there is no template label. */
8680
@Input('label') textLabel: string = '';
@@ -146,7 +140,7 @@ export class MatTab implements OnInit, OnChanges, OnDestroy {
146140

147141
ngOnInit(): void {
148142
this._contentPortal = new TemplatePortal(
149-
this._explicitContent || this._implicitContent,
143+
this._explicitContent || this._implicitContent!,
150144
this._viewContainerRef,
151145
);
152146
}

0 commit comments

Comments
 (0)