@@ -15,7 +15,7 @@ import {
1515 TAB ,
1616 UP_ARROW ,
1717} from '@angular/cdk/keycodes' ;
18- import { OverlayContainer , OverlayModule } from '@angular/cdk/overlay' ;
18+ import { Overlay , OverlayContainer , OverlayModule } from '@angular/cdk/overlay' ;
1919import { ScrollDispatcher } from '@angular/cdk/scrolling' ;
2020import {
2121 createKeyboardEvent ,
@@ -56,15 +56,15 @@ import {
5656 ReactiveFormsModule ,
5757 Validators ,
5858} from '@angular/forms' ;
59- import { ErrorStateMatcher , MatOption , MatOptionSelectionChange } from '../core' ;
60- import { FloatLabelType , MAT_FORM_FIELD_DEFAULT_OPTIONS , MatFormFieldModule } from '../form-field' ;
61- import { MAT_SELECT_CONFIG , MatSelectConfig } from '../select' ;
6259import { By } from '@angular/platform-browser' ;
6360import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
6461import { EMPTY , Observable , Subject , Subscription } from 'rxjs' ;
6562import { map } from 'rxjs/operators' ;
63+ import { ErrorStateMatcher , MatOption , MatOptionSelectionChange } from '../core' ;
64+ import { FloatLabelType , MAT_FORM_FIELD_DEFAULT_OPTIONS , MatFormFieldModule } from '../form-field' ;
65+ import { MAT_SELECT_CONFIG , MatSelectConfig } from '../select' ;
6666import { MatSelectModule } from './index' ;
67- import { MatSelect } from './select' ;
67+ import { MAT_SELECT_SCROLL_STRATEGY , MatSelect } from './select' ;
6868import {
6969 getMatSelectDynamicMultipleError ,
7070 getMatSelectNonArrayValueError ,
@@ -1782,6 +1782,38 @@ describe('MatSelect', () => {
17821782 . withContext ( 'Expected select element to remain focused.' )
17831783 . toBe ( true ) ;
17841784 } ) ) ;
1785+
1786+ it ( 'should close the panel when MAT_SELECT_SCROLL_STRATEGY token was defined with overlay close method' , fakeAsync ( ( ) => {
1787+ waitForAsync ( ( ) =>
1788+ configureMatSelectTestingModule (
1789+ [ ] ,
1790+ [
1791+ {
1792+ provide : MAT_SELECT_SCROLL_STRATEGY ,
1793+ useFactory : ( overlay : Overlay ) => {
1794+ return ( ) => overlay . scrollStrategies . close ( ) ;
1795+ } ,
1796+ deps : [ Overlay ] ,
1797+ } ,
1798+ ] ,
1799+ ) ,
1800+ ) ;
1801+
1802+ fixture = TestBed . createComponent ( BasicSelect ) ;
1803+ fixture . detectChanges ( ) ;
1804+
1805+ const selectElement = fixture . nativeElement . querySelector ( '.mat-mdc-select' ) ;
1806+
1807+ dispatchFakeEvent ( selectElement , 'click' ) ;
1808+ fixture . detectChanges ( ) ;
1809+
1810+ dispatchFakeEvent ( window , 'scroll' ) ;
1811+ fixture . detectChanges ( ) ;
1812+
1813+ flush ( ) ;
1814+
1815+ expect ( fixture . componentInstance . select . panelOpen ) . toBe ( false ) ;
1816+ } ) ) ;
17851817 } ) ;
17861818
17871819 describe ( 'selection logic' , ( ) => {
0 commit comments