Skip to content

Commit e7fea69

Browse files
crisbetowagnermaciel
authored andcommitted
fix(material/tabs): projected tabs not being picked up (#21794)
Fixes an error that is thrown when tabs are projected in from another component into a `mat-tab-group`. Fixes #21770. (cherry picked from commit e7a64d3)
1 parent 96a65d9 commit e7fea69

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/material/tabs/tab-group.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements
276276
this._allTabs.changes
277277
.pipe(startWith(this._allTabs))
278278
.subscribe((tabs: QueryList<MatTab>) => {
279-
this._tabs.reset(tabs.filter(tab => tab._closestTabGroup === this));
279+
this._tabs.reset(tabs.filter(tab => {
280+
return tab._closestTabGroup === this || !tab._closestTabGroup;
281+
}));
280282
this._tabs.notifyOnChanges();
281283
});
282284
}

src/material/tabs/tab.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
ViewEncapsulation,
2424
InjectionToken,
2525
Inject,
26+
Optional,
2627
} from '@angular/core';
2728
import {CanDisable, CanDisableCtor, mixinDisabled} from '@angular/material/core';
2829
import {Subject} from 'rxjs';
@@ -109,7 +110,7 @@ export class MatTab extends _MatTabMixinBase implements OnInit, CanDisable, OnCh
109110

110111
constructor(
111112
private _viewContainerRef: ViewContainerRef,
112-
@Inject(MAT_TAB_GROUP) public _closestTabGroup: any) {
113+
@Inject(MAT_TAB_GROUP) @Optional() public _closestTabGroup: any) {
113114
super();
114115
}
115116

tools/public_api_guard/material/tabs.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export declare class MatTab extends _MatTabMixinBase implements OnInit, CanDisab
152152
ngOnInit(): void;
153153
static ngAcceptInputType_disabled: BooleanInput;
154154
static ɵcmp: i0.ɵɵComponentDeclaration<MatTab, "mat-tab", ["matTab"], { "disabled": "disabled"; "textLabel": "label"; "ariaLabel": "aria-label"; "ariaLabelledby": "aria-labelledby"; }, {}, ["templateLabel", "_explicitContent"], ["*"]>;
155-
static ɵfac: i0.ɵɵFactoryDeclaration<MatTab, never>;
155+
static ɵfac: i0.ɵɵFactoryDeclaration<MatTab, [null, { optional: true; }]>;
156156
}
157157

158158
export declare class MatTabBody extends _MatTabBodyBase {

0 commit comments

Comments
 (0)