Skip to content

Commit b7b7bd0

Browse files
crisbetommalerba
authored andcommitted
fix(tabs): custom QueryList not being cleaned up (#17548)
We create a custom `QueryList` called `_tabs` to capture only the tabs that belong to the current tab group, however since it's something that we create manually. it won't be cleaned up automatically. These changes ensure that it's cleaned up.
1 parent 584ad3f commit b7b7bd0

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ describe('MatTabGroup', () => {
280280
.toHaveBeenCalledWith(jasmine.objectContaining({index: 0}));
281281
});
282282

283+
it('should clean up the tabs QueryList on destroy', () => {
284+
const component: MatTabGroup =
285+
fixture.debugElement.query(By.css('mat-tab-group'))!.componentInstance;
286+
const spy = jasmine.createSpy('complete spy');
287+
const subscription = component._tabs.changes.subscribe({complete: spy});
288+
289+
fixture.destroy();
290+
291+
expect(spy).toHaveBeenCalled();
292+
subscription.unsubscribe();
293+
});
294+
283295
});
284296

285297
describe('aria labelling', () => {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ describe('MatTabGroup', () => {
279279
.toHaveBeenCalledWith(jasmine.objectContaining({index: 0}));
280280
});
281281

282+
it('should clean up the tabs QueryList on destroy', () => {
283+
const component: MatTabGroup =
284+
fixture.debugElement.query(By.css('mat-tab-group'))!.componentInstance;
285+
const spy = jasmine.createSpy('complete spy');
286+
const subscription = component._tabs.changes.subscribe({complete: spy});
287+
288+
fixture.destroy();
289+
290+
expect(spy).toHaveBeenCalled();
291+
subscription.unsubscribe();
292+
});
293+
282294
});
283295

284296
describe('aria labelling', () => {

src/material/tabs/tab-group.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements
279279
}
280280

281281
ngOnDestroy() {
282+
this._tabs.destroy();
282283
this._tabsSubscription.unsubscribe();
283284
this._tabLabelSubscription.unsubscribe();
284285
}

0 commit comments

Comments
 (0)