Skip to content
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

fix(material/select): close panel on detach output event #30634

Merged
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
1 change: 1 addition & 0 deletions src/material/select/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
[cdkConnectedOverlayPositions]="_positions"
[cdkConnectedOverlayWidth]="_overlayWidth"
[cdkConnectedOverlayFlexibleDimensions]="true"
(detach)="close()"
(backdropClick)="close()"
(overlayKeydown)="_handleOverlayKeydown($event)">
<div
Expand Down
48 changes: 43 additions & 5 deletions src/material/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TAB,
UP_ARROW,
} from '@angular/cdk/keycodes';
import {OverlayContainer, OverlayModule} from '@angular/cdk/overlay';
import {CloseScrollStrategy, Overlay, OverlayContainer, OverlayModule} from '@angular/cdk/overlay';
import {ScrollDispatcher} from '@angular/cdk/scrolling';
import {
createKeyboardEvent,
Expand Down Expand Up @@ -56,15 +56,15 @@ import {
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import {ErrorStateMatcher, MatOption, MatOptionSelectionChange} from '../core';
import {FloatLabelType, MAT_FORM_FIELD_DEFAULT_OPTIONS, MatFormFieldModule} from '../form-field';
import {MAT_SELECT_CONFIG, MatSelectConfig} from '../select';
import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {EMPTY, Observable, Subject, Subscription} from 'rxjs';
import {map} from 'rxjs/operators';
import {ErrorStateMatcher, MatOption, MatOptionSelectionChange} from '../core';
import {FloatLabelType, MAT_FORM_FIELD_DEFAULT_OPTIONS, MatFormFieldModule} from '../form-field';
import {MAT_SELECT_CONFIG, MatSelectConfig} from '../select';
import {MatSelectModule} from './index';
import {MatSelect} from './select';
import {MAT_SELECT_SCROLL_STRATEGY, MatSelect} from './select';
import {
getMatSelectDynamicMultipleError,
getMatSelectNonArrayValueError,
Expand Down Expand Up @@ -1782,6 +1782,44 @@ describe('MatSelect', () => {
.withContext('Expected select element to remain focused.')
.toBe(true);
}));

it('should close the panel on scroll event when MAT_SELECT_SCROLL_STRATEGY token was defined with CloseScrollStrategy', fakeAsync(() => {
// Need to recreate the testing module, because the issue we're
// testing for only the MAT_SELECT_SCROLL_STRATEGY is defined with thw
// is defined with the CloseScrollStrategy

TestBed.resetTestingModule();
TestBed.configureTestingModule({
imports: [MatFormFieldModule, MatSelectModule],
declarations: [BasicSelect],
providers: [
{
provide: MAT_SELECT_SCROLL_STRATEGY,
useFactory: (overlay: Overlay) => (): CloseScrollStrategy =>
overlay.scrollStrategies.close(),
deps: [Overlay],
},
{
provide: ScrollDispatcher,
useFactory: () => ({
scrolled: () => scrolledSubject,
}),
},
],
});

fixture = TestBed.createComponent(BasicSelect);
fixture.detectChanges();

const select = fixture.componentInstance.select;
select.open();

scrolledSubject.next();
fixture.detectChanges();
flush();

expect(select.panelOpen).toBe(false);
}));
});

describe('selection logic', () => {
Expand Down
Loading