diff --git a/src/material/select/select.html b/src/material/select/select.html index 9a9b147c3c51..6eaecee7f5c3 100644 --- a/src/material/select/select.html +++ b/src/material/select/select.html @@ -40,6 +40,7 @@ [cdkConnectedOverlayPositions]="_positions" [cdkConnectedOverlayWidth]="_overlayWidth" [cdkConnectedOverlayFlexibleDimensions]="true" + (detach)="close()" (backdropClick)="close()" (overlayKeydown)="_handleOverlayKeydown($event)">
{ .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', () => {