@@ -19,14 +19,17 @@ import {Dir} from '../core/rtl/dir';
19
19
import {
20
20
ControlValueAccessor , FormControl , FormsModule , NG_VALUE_ACCESSOR , ReactiveFormsModule
21
21
} from '@angular/forms' ;
22
+ import { Subject } from 'rxjs/Subject' ;
22
23
import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
23
24
import { dispatchFakeEvent } from '../core/testing/dispatch-events' ;
24
25
import { wrappedErrorMessage } from '../core/testing/wrapped-error-message' ;
26
+ import { ScrollDispatcher } from '../core/overlay/scroll/scroll-dispatcher' ;
25
27
26
28
27
29
describe ( 'MdSelect' , ( ) => {
28
30
let overlayContainerElement : HTMLElement ;
29
31
let dir : { value : string } ;
32
+ let scrolledSubject = new Subject ( ) ;
30
33
31
34
beforeEach ( async ( ( ) => {
32
35
TestBed . configureTestingModule ( {
@@ -64,7 +67,12 @@ describe('MdSelect', () => {
64
67
{ provide : Dir , useFactory : ( ) => {
65
68
return dir = { value : 'ltr' } ;
66
69
} } ,
67
- { provide : ViewportRuler , useClass : FakeViewportRuler }
70
+ { provide : ViewportRuler , useClass : FakeViewportRuler } ,
71
+ { provide : ScrollDispatcher , useFactory : ( ) => {
72
+ return { scrolled : ( delay : number , callback : ( ) => any ) => {
73
+ return scrolledSubject . asObservable ( ) . subscribe ( callback ) ;
74
+ } } ;
75
+ } }
68
76
]
69
77
} ) ;
70
78
@@ -918,7 +926,6 @@ describe('MdSelect', () => {
918
926
checkTriggerAlignedWithOption ( 0 ) ;
919
927
} ) ;
920
928
921
-
922
929
it ( 'should align a centered option properly when scrolled' , ( ) => {
923
930
// Give the select enough space to open
924
931
fixture . componentInstance . heightBelow = 400 ;
@@ -936,6 +943,23 @@ describe('MdSelect', () => {
936
943
checkTriggerAlignedWithOption ( 4 ) ;
937
944
} ) ;
938
945
946
+ it ( 'should align a centered option properly when scrolling while the panel is open' , ( ) => {
947
+ // Give the select enough space to open
948
+ fixture . componentInstance . heightBelow = 400 ;
949
+ fixture . componentInstance . heightAbove = 400 ;
950
+ fixture . componentInstance . control . setValue ( 'chips-4' ) ;
951
+ fixture . detectChanges ( ) ;
952
+
953
+ trigger . click ( ) ;
954
+ fixture . detectChanges ( ) ;
955
+
956
+ setScrollTop ( 100 ) ;
957
+ scrolledSubject . next ( ) ;
958
+ fixture . detectChanges ( ) ;
959
+
960
+ checkTriggerAlignedWithOption ( 4 ) ;
961
+ } ) ;
962
+
939
963
it ( 'should fall back to "above" positioning properly when scrolled' , ( ) => {
940
964
// Give the select insufficient space to open below the trigger
941
965
fixture . componentInstance . heightBelow = 100 ;
0 commit comments