Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/components/select/select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6597,6 +6597,38 @@ describe('KbqSelect', () => {
});
});

describe('overlay teardown', () => {
let fixture: ComponentFixture<MultiSelect>;
let testInstance: MultiSelect;

beforeEach(fakeAsync(() => {
configureKbqSelectTestingModule([MultiSelect]);
fixture = TestBed.createComponent(MultiSelect);
testInstance = fixture.componentInstance;
fixture.detectChanges();
flush();
}));

// Regression: the delayed `options.changes` subscription set up in `onAttached` used to outlive the
// component. Destroying the select (e.g. closing a modal) disposed the overlay before the 1ms timer
// fired, so the late callback hit `resetOverlay` on a null overlay element and threw
// "Cannot read properties of null (reading 'style')".
it('should not throw when destroyed before the delayed options.changes callback fires', fakeAsync(() => {
testInstance.select().open();
fixture.detectChanges();
flush();

// Re-render the options so the select's `options.changes` emits and schedules the delayed callback.
testInstance.foods = [{ value: 'ramen-0', viewValue: 'Ramen' }];
fixture.detectChanges();

// Destroying disposes the overlay (overlay element becomes null) before the 1ms timer runs.
fixture.destroy();

expect(() => tick(1)).not.toThrow();
}));
});

describe('multiline', () => {
let fixture: ComponentFixture<MultiSelectWithConfigurableInputs>;
let testInstance: MultiSelectWithConfigurableInputs;
Expand Down
4 changes: 3 additions & 1 deletion packages/components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,9 @@ export class KbqSelect
this.subscribeToScrolledToBottom();
});

this.options.changes.pipe(delay(1)).subscribe(() => this.setOverlayPosition());
this.options.changes
.pipe(delay(1), takeUntilDestroyed(this.destroyRef))
.subscribe(() => this.setOverlayPosition());

this.closeSubscription = this.closingActions().subscribe(() => this.close());
}
Expand Down
Loading