@@ -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 : 'ltr' | 'rtl' } ;
32
+ let scrolledSubject = new Subject ( ) ;
30
33
31
34
beforeEach ( async ( ( ) => {
32
35
TestBed . configureTestingModule ( {
@@ -67,7 +70,12 @@ describe('MdSelect', () => {
67
70
{ provide : Dir , useFactory : ( ) => {
68
71
return dir = { value : 'ltr' } ;
69
72
} } ,
70
- { provide : ViewportRuler , useClass : FakeViewportRuler }
73
+ { provide : ViewportRuler , useClass : FakeViewportRuler } ,
74
+ { provide : ScrollDispatcher , useFactory : ( ) => {
75
+ return { scrolled : ( delay : number , callback : ( ) => any ) => {
76
+ return scrolledSubject . asObservable ( ) . subscribe ( callback ) ;
77
+ } } ;
78
+ } }
71
79
]
72
80
} ) ;
73
81
@@ -955,7 +963,6 @@ describe('MdSelect', () => {
955
963
checkTriggerAlignedWithOption ( 0 ) ;
956
964
} ) ;
957
965
958
-
959
966
it ( 'should align a centered option properly when scrolled' , ( ) => {
960
967
// Give the select enough space to open
961
968
fixture . componentInstance . heightBelow = 400 ;
@@ -973,6 +980,22 @@ describe('MdSelect', () => {
973
980
checkTriggerAlignedWithOption ( 4 ) ;
974
981
} ) ;
975
982
983
+ it ( 'should align a centered option properly when scrolling while the panel is open' , ( ) => {
984
+ fixture . componentInstance . heightBelow = 400 ;
985
+ fixture . componentInstance . heightAbove = 400 ;
986
+ fixture . componentInstance . control . setValue ( 'chips-4' ) ;
987
+ fixture . detectChanges ( ) ;
988
+
989
+ trigger . click ( ) ;
990
+ fixture . detectChanges ( ) ;
991
+
992
+ setScrollTop ( 100 ) ;
993
+ scrolledSubject . next ( ) ;
994
+ fixture . detectChanges ( ) ;
995
+
996
+ checkTriggerAlignedWithOption ( 4 ) ;
997
+ } ) ;
998
+
976
999
it ( 'should fall back to "above" positioning properly when scrolled' , ( ) => {
977
1000
// Give the select insufficient space to open below the trigger
978
1001
fixture . componentInstance . heightBelow = 100 ;
0 commit comments