@@ -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 { CloseScrollStrategy , 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,44 @@ 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+ // Need to recreate the testing module, because the issue we're
1788+ // testing for only the MAT_SELECT_SCROLL_STRATEGY is defined with thw
1789+ // is defined with the CloseScrollStrategy
1790+
1791+ TestBed . resetTestingModule ( ) ;
1792+ TestBed . configureTestingModule ( {
1793+ imports : [ MatFormFieldModule , MatSelectModule ] ,
1794+ declarations : [ BasicSelect ] ,
1795+ providers : [
1796+ {
1797+ provide : MAT_SELECT_SCROLL_STRATEGY ,
1798+ useFactory : ( overlay : Overlay ) => ( ) : CloseScrollStrategy =>
1799+ overlay . scrollStrategies . close ( ) ,
1800+ deps : [ Overlay ] ,
1801+ } ,
1802+ {
1803+ provide : ScrollDispatcher ,
1804+ useFactory : ( ) => ( {
1805+ scrolled : ( ) => scrolledSubject ,
1806+ } ) ,
1807+ } ,
1808+ ] ,
1809+ } ) ;
1810+
1811+ fixture = TestBed . createComponent ( BasicSelect ) ;
1812+ fixture . detectChanges ( ) ;
1813+
1814+ const select = fixture . componentInstance . select ;
1815+ select . open ( ) ;
1816+
1817+ scrolledSubject . next ( ) ;
1818+ fixture . detectChanges ( ) ;
1819+ flush ( ) ;
1820+
1821+ expect ( select . panelOpen ) . toBe ( false ) ;
1822+ } ) ) ;
17851823 } ) ;
17861824
17871825 describe ( 'selection logic' , ( ) => {
0 commit comments