Skip to content

Commit

Permalink
fix(tabs): custom QueryList not being cleaned up (#17548)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto authored and mmalerba committed Nov 11, 2019
1 parent 584ad3f commit b7b7bd0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/material-experimental/mdc-tabs/tab-group.spec.ts
Expand Up @@ -280,6 +280,18 @@ describe('MatTabGroup', () => {
.toHaveBeenCalledWith(jasmine.objectContaining({index: 0}));
});

it('should clean up the tabs QueryList on destroy', () => {
const component: MatTabGroup =
fixture.debugElement.query(By.css('mat-tab-group'))!.componentInstance;
const spy = jasmine.createSpy('complete spy');
const subscription = component._tabs.changes.subscribe({complete: spy});

fixture.destroy();

expect(spy).toHaveBeenCalled();
subscription.unsubscribe();
});

});

describe('aria labelling', () => {
Expand Down
12 changes: 12 additions & 0 deletions src/material/tabs/tab-group.spec.ts
Expand Up @@ -279,6 +279,18 @@ describe('MatTabGroup', () => {
.toHaveBeenCalledWith(jasmine.objectContaining({index: 0}));
});

it('should clean up the tabs QueryList on destroy', () => {
const component: MatTabGroup =
fixture.debugElement.query(By.css('mat-tab-group'))!.componentInstance;
const spy = jasmine.createSpy('complete spy');
const subscription = component._tabs.changes.subscribe({complete: spy});

fixture.destroy();

expect(spy).toHaveBeenCalled();
subscription.unsubscribe();
});

});

describe('aria labelling', () => {
Expand Down
1 change: 1 addition & 0 deletions src/material/tabs/tab-group.ts
Expand Up @@ -279,6 +279,7 @@ export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements
}

ngOnDestroy() {
this._tabs.destroy();
this._tabsSubscription.unsubscribe();
this._tabLabelSubscription.unsubscribe();
}
Expand Down

0 comments on commit b7b7bd0

Please sign in to comment.