@@ -15,7 +15,7 @@ import {
15
15
TAB ,
16
16
UP_ARROW ,
17
17
} from '@angular/cdk/keycodes' ;
18
- import { OverlayContainer , OverlayModule } from '@angular/cdk/overlay' ;
18
+ import { CloseScrollStrategy , Overlay , OverlayContainer , OverlayModule } from '@angular/cdk/overlay' ;
19
19
import { ScrollDispatcher } from '@angular/cdk/scrolling' ;
20
20
import {
21
21
createKeyboardEvent ,
@@ -56,15 +56,15 @@ import {
56
56
ReactiveFormsModule ,
57
57
Validators ,
58
58
} 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' ;
62
59
import { By } from '@angular/platform-browser' ;
63
60
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
64
61
import { EMPTY , Observable , Subject , Subscription } from 'rxjs' ;
65
62
import { 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' ;
66
66
import { MatSelectModule } from './index' ;
67
- import { MatSelect } from './select' ;
67
+ import { MAT_SELECT_SCROLL_STRATEGY , MatSelect } from './select' ;
68
68
import {
69
69
getMatSelectDynamicMultipleError ,
70
70
getMatSelectNonArrayValueError ,
@@ -1782,6 +1782,44 @@ describe('MatSelect', () => {
1782
1782
. withContext ( 'Expected select element to remain focused.' )
1783
1783
. toBe ( true ) ;
1784
1784
} ) ) ;
1785
+
1786
+ it ( 'should close the panel on scroll event when MAT_SELECT_SCROLL_STRATEGY token was defined with CloseScrollStrategy' , 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
+ } ) ) ;
1785
1823
} ) ;
1786
1824
1787
1825
describe ( 'selection logic' , ( ) => {
0 commit comments