Skip to content

Commit

Permalink
fix(cdk-experimental/combobox): not cleaning up overlay on destroy (#…
Browse files Browse the repository at this point in the history
…20407)

The combobox was leaving behind its open overlays when it gets destroyed, because it wasn't calling `OverlayRef.dispose`.
  • Loading branch information
crisbeto committed Aug 28, 2020
1 parent f795b9d commit 6d1a259
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/cdk-experimental/combobox/combobox.spec.ts
Expand Up @@ -179,6 +179,18 @@ describe('Combobox', () => {

expect(comboboxInstance.isOpen()).toBeFalse();
});

it('should clean up the overlay on destroy', () => {
expect(document.querySelectorAll('.cdk-overlay-pane').length).toBe(0);

dispatchMouseEvent(comboboxElement, 'click');
fixture.detectChanges();
expect(document.querySelectorAll('.cdk-overlay-pane').length).toBe(1);

fixture.destroy();
expect(document.querySelectorAll('.cdk-overlay-pane').length).toBe(0);
});

});

describe('with a coerce open action property function', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/cdk-experimental/combobox/combobox.ts
Expand Up @@ -114,6 +114,10 @@ export class CdkCombobox<T = unknown> implements OnDestroy, AfterContentInit {
}

ngOnDestroy() {
if (this._overlayRef) {
this._overlayRef.dispose();
}

this.opened.complete();
this.closed.complete();
this.panelValueChanged.complete();
Expand Down

0 comments on commit 6d1a259

Please sign in to comment.