Skip to content

fix(material/select): avoid error if panel is closed too quickly #30408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2025
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
20 changes: 20 additions & 0 deletions src/material/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,26 @@ describe('MatSelect', () => {
expect(() => fixture.componentInstance.select.open()).not.toThrow();
});

it('should not throw when closing too quickly after opening', () => {
// Need to recreate the testing module, because the issue we're
// testing for only happens when animations are enabled.
TestBed.resetTestingModule();
TestBed.configureTestingModule({
imports: [MatFormFieldModule, MatSelectModule],
declarations: [BasicSelect],
});

fixture = TestBed.createComponent(BasicSelect);
fixture.detectChanges();
const select = fixture.componentInstance.select;

expect(() => {
select.open();
select.close();
}).not.toThrow();
expect(select.panelOpen).toBe(false);
});

it('should open the panel when trigger is clicked', fakeAsync(() => {
trigger.click();
fixture.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/material/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ export class MatSelect

/** Triggers the exit animation and detaches the overlay at the end. */
private _exitAndDetach() {
if (this._animationsDisabled) {
if (this._animationsDisabled || !this.panel) {
this._overlayDir.detachOverlay();
return;
}
Expand Down
Loading