@@ -19,15 +19,18 @@ 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 , dispatchKeyboardEvent } from '../core/testing/dispatch-events' ;
24
25
import { wrappedErrorMessage } from '../core/testing/wrapped-error-message' ;
25
26
import { TAB } from '../core/keyboard/keycodes' ;
27
+ import { ScrollDispatcher } from '../core/overlay/scroll/scroll-dispatcher' ;
26
28
27
29
28
30
describe ( 'MdSelect' , ( ) => {
29
31
let overlayContainerElement : HTMLElement ;
30
32
let dir : { value : 'ltr' | 'rtl' } ;
33
+ let scrolledSubject = new Subject ( ) ;
31
34
32
35
beforeEach ( async ( ( ) => {
33
36
TestBed . configureTestingModule ( {
@@ -69,7 +72,12 @@ describe('MdSelect', () => {
69
72
{ provide : Dir , useFactory : ( ) => {
70
73
return dir = { value : 'ltr' } ;
71
74
} } ,
72
- { provide : ViewportRuler , useClass : FakeViewportRuler }
75
+ { provide : ViewportRuler , useClass : FakeViewportRuler } ,
76
+ { provide : ScrollDispatcher , useFactory : ( ) => {
77
+ return { scrolled : ( delay : number , callback : ( ) => any ) => {
78
+ return scrolledSubject . asObservable ( ) . subscribe ( callback ) ;
79
+ } } ;
80
+ } }
73
81
]
74
82
} ) ;
75
83
@@ -971,7 +979,6 @@ describe('MdSelect', () => {
971
979
checkTriggerAlignedWithOption ( 0 ) ;
972
980
} ) ;
973
981
974
-
975
982
it ( 'should align a centered option properly when scrolled' , ( ) => {
976
983
// Give the select enough space to open
977
984
fixture . componentInstance . heightBelow = 400 ;
@@ -989,6 +996,22 @@ describe('MdSelect', () => {
989
996
checkTriggerAlignedWithOption ( 4 ) ;
990
997
} ) ;
991
998
999
+ it ( 'should align a centered option properly when scrolling while the panel is open' , ( ) => {
1000
+ fixture . componentInstance . heightBelow = 400 ;
1001
+ fixture . componentInstance . heightAbove = 400 ;
1002
+ fixture . componentInstance . control . setValue ( 'chips-4' ) ;
1003
+ fixture . detectChanges ( ) ;
1004
+
1005
+ trigger . click ( ) ;
1006
+ fixture . detectChanges ( ) ;
1007
+
1008
+ setScrollTop ( 100 ) ;
1009
+ scrolledSubject . next ( ) ;
1010
+ fixture . detectChanges ( ) ;
1011
+
1012
+ checkTriggerAlignedWithOption ( 4 ) ;
1013
+ } ) ;
1014
+
992
1015
it ( 'should fall back to "above" positioning properly when scrolled' , ( ) => {
993
1016
// Give the select insufficient space to open below the trigger
994
1017
fixture . componentInstance . heightBelow = 100 ;
0 commit comments