Skip to content

Commit 14d9311

Browse files
lazergcrisbeto
authored andcommitted
fix(aria/combobox): error when popup is destroyed before first change detection (#33974)
(cherry picked from commit bbc5750)
1 parent feb80c2 commit 14d9311

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎src/aria/combobox/combobox-popup.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ import {COMBOBOX_POPUP} from './combobox-tokens';
3535
export class ComboboxPopup implements OnInit, OnDestroy {
3636
private readonly _deferredContent = inject(DeferredContent);
3737

38+
/** The combobox that the popup is registered with. */
39+
private _registeredCombobox: Combobox | undefined;
40+
3841
/** The combobox that the popup belongs to. */
3942
readonly combobox = input.required<Combobox>();
4043

@@ -60,12 +63,13 @@ export class ComboboxPopup implements OnInit, OnDestroy {
6063
});
6164

6265
ngOnInit() {
63-
this.combobox()._registerPopup(this);
64-
this._deferredContent.deferredContentAware.set(this.combobox());
66+
this._registeredCombobox = this.combobox();
67+
this._registeredCombobox._registerPopup(this);
68+
this._deferredContent.deferredContentAware.set(this._registeredCombobox);
6569
}
6670

6771
ngOnDestroy() {
68-
this.combobox()._unregisterPopup();
72+
this._registeredCombobox?._unregisterPopup();
6973
}
7074

7175
/** Registers a widget with the popup. */

‎src/aria/combobox/combobox.spec.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,11 @@ describe('Combobox', () => {
13191319
expect(comboboxElement.getAttribute('aria-expanded')).toBe('true');
13201320
});
13211321
});
1322+
1323+
it('should not throw when destroyed before the first change detection', () => {
1324+
const fixture = TestBed.createComponent(ComboboxListboxExample);
1325+
expect(() => fixture.destroy()).not.toThrow();
1326+
});
13221327
});
13231328

13241329
@Component({

0 commit comments

Comments
 (0)