Skip to content

Commit 6d1a259

Browse files
authored
fix(cdk-experimental/combobox): not cleaning up overlay on destroy (#20407)
The combobox was leaving behind its open overlays when it gets destroyed, because it wasn't calling `OverlayRef.dispose`.
1 parent f795b9d commit 6d1a259

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/cdk-experimental/combobox/combobox.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ describe('Combobox', () => {
179179

180180
expect(comboboxInstance.isOpen()).toBeFalse();
181181
});
182+
183+
it('should clean up the overlay on destroy', () => {
184+
expect(document.querySelectorAll('.cdk-overlay-pane').length).toBe(0);
185+
186+
dispatchMouseEvent(comboboxElement, 'click');
187+
fixture.detectChanges();
188+
expect(document.querySelectorAll('.cdk-overlay-pane').length).toBe(1);
189+
190+
fixture.destroy();
191+
expect(document.querySelectorAll('.cdk-overlay-pane').length).toBe(0);
192+
});
193+
182194
});
183195

184196
describe('with a coerce open action property function', () => {

src/cdk-experimental/combobox/combobox.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ export class CdkCombobox<T = unknown> implements OnDestroy, AfterContentInit {
114114
}
115115

116116
ngOnDestroy() {
117+
if (this._overlayRef) {
118+
this._overlayRef.dispose();
119+
}
120+
117121
this.opened.complete();
118122
this.closed.complete();
119123
this.panelValueChanged.complete();

0 commit comments

Comments
 (0)