@@ -162,7 +162,7 @@ describe('CdkVirtualScrollViewport', () => {
162
162
fixture . detectChanges ( ) ;
163
163
flush ( ) ;
164
164
165
- expect ( viewport . elementRef . nativeElement . scrollTop ) . toBe ( testComponent . itemSize * 2 ) ;
165
+ expect ( viewport . measureScrollOffset ( ) ) . toBe ( testComponent . itemSize * 2 ) ;
166
166
expect ( viewport . getRenderedRange ( ) ) . toEqual ( { start : 2 , end : 6 } ) ;
167
167
} ) ) ;
168
168
@@ -174,7 +174,7 @@ describe('CdkVirtualScrollViewport', () => {
174
174
fixture . detectChanges ( ) ;
175
175
flush ( ) ;
176
176
177
- expect ( viewport . elementRef . nativeElement . scrollTop ) . toBe ( testComponent . itemSize * 2 ) ;
177
+ expect ( viewport . measureScrollOffset ( ) ) . toBe ( testComponent . itemSize * 2 ) ;
178
178
expect ( viewport . getRenderedRange ( ) ) . toEqual ( { start : 2 , end : 6 } ) ;
179
179
} ) ) ;
180
180
@@ -187,7 +187,7 @@ describe('CdkVirtualScrollViewport', () => {
187
187
fixture . detectChanges ( ) ;
188
188
flush ( ) ;
189
189
190
- expect ( viewport . elementRef . nativeElement . scrollLeft ) . toBe ( testComponent . itemSize * 2 ) ;
190
+ expect ( viewport . measureScrollOffset ( ) ) . toBe ( testComponent . itemSize * 2 ) ;
191
191
expect ( viewport . getRenderedRange ( ) ) . toEqual ( { start : 2 , end : 6 } ) ;
192
192
} ) ) ;
193
193
@@ -200,7 +200,7 @@ describe('CdkVirtualScrollViewport', () => {
200
200
fixture . detectChanges ( ) ;
201
201
flush ( ) ;
202
202
203
- expect ( viewport . elementRef . nativeElement . scrollLeft ) . toBe ( testComponent . itemSize * 2 ) ;
203
+ expect ( viewport . measureScrollOffset ( ) ) . toBe ( testComponent . itemSize * 2 ) ;
204
204
expect ( viewport . getRenderedRange ( ) ) . toEqual ( { start : 2 , end : 6 } ) ;
205
205
} ) ) ;
206
206
@@ -620,23 +620,22 @@ describe('CdkVirtualScrollViewport', () => {
620
620
testComponent . orientation = 'horizontal' ;
621
621
finishInit ( fixture ) ;
622
622
623
- expect ( viewportEl . scrollLeft ) . toBe (
624
- testComponent . itemSize * testComponent . items . length - testComponent . viewportSize ) ;
623
+ expect ( viewport . measureScrollOffset ( 'right' ) ) . toBe ( 0 ) ;
625
624
expect ( contentWrapperEl . style . transform ) . toMatch ( / t r a n s l a t e X \( 0 ( p x ) ? \) / ) ;
626
- expect ( ( contentWrapperEl . children [ 0 ] as HTMLElement ) . innerText ) . toBe ( '0 - 0' ) ;
625
+ expect ( ( contentWrapperEl . children [ 0 ] as HTMLElement ) . innerText . trim ( ) ) . toBe ( '0 - 0' ) ;
627
626
} ) ) ;
628
627
629
628
it ( 'should scroll through items as user scrolls to the left in horizontal mode' ,
630
629
fakeAsync ( ( ) => {
631
630
testComponent . orientation = 'horizontal' ;
632
631
finishInit ( fixture ) ;
633
632
634
- triggerScroll ( viewport , 0 ) ;
633
+ triggerScroll ( viewport , testComponent . itemSize * testComponent . items . length ) ;
635
634
fixture . detectChanges ( ) ;
636
635
flush ( ) ;
637
636
638
637
expect ( contentWrapperEl . style . transform ) . toBe ( 'translateX(-300px)' ) ;
639
- expect ( ( contentWrapperEl . children [ 0 ] as HTMLElement ) . innerText ) . toBe ( '6 - 6' ) ;
638
+ expect ( ( contentWrapperEl . children [ 0 ] as HTMLElement ) . innerText . trim ( ) ) . toBe ( '6 - 6' ) ;
640
639
} ) ) ;
641
640
642
641
it ( 'should interpret scrollToOffset amount as an offset from the right in horizontal mode' ,
@@ -649,8 +648,7 @@ describe('CdkVirtualScrollViewport', () => {
649
648
fixture . detectChanges ( ) ;
650
649
flush ( ) ;
651
650
652
- expect ( viewportEl . scrollLeft ) . toBe ( testComponent . itemSize * testComponent . items . length -
653
- testComponent . viewportSize - 100 ) ;
651
+ expect ( viewport . measureScrollOffset ( 'right' ) ) . toBe ( 100 ) ;
654
652
} ) ) ;
655
653
656
654
it ( 'should scroll to the correct index in horizontal mode' , fakeAsync ( ( ) => {
@@ -662,7 +660,7 @@ describe('CdkVirtualScrollViewport', () => {
662
660
fixture . detectChanges ( ) ;
663
661
flush ( ) ;
664
662
665
- expect ( ( contentWrapperEl . children [ 0 ] as HTMLElement ) . innerText ) . toBe ( '2 - 2' ) ;
663
+ expect ( ( contentWrapperEl . children [ 0 ] as HTMLElement ) . innerText . trim ( ) ) . toBe ( '2 - 2' ) ;
666
664
} ) ) ;
667
665
668
666
it ( 'should emit the scrolled to index in horizontal mode' , fakeAsync ( ( ) => {
@@ -701,11 +699,7 @@ function finishInit(fixture: ComponentFixture<any>) {
701
699
/** Trigger a scroll event on the viewport (optionally setting a new scroll offset). */
702
700
function triggerScroll ( viewport : CdkVirtualScrollViewport , offset ?: number ) {
703
701
if ( offset !== undefined ) {
704
- if ( viewport . orientation == 'horizontal' ) {
705
- viewport . elementRef . nativeElement . scrollLeft = offset ;
706
- } else {
707
- viewport . elementRef . nativeElement . scrollTop = offset ;
708
- }
702
+ viewport . scrollToOffset ( offset ) ;
709
703
}
710
704
dispatchFakeEvent ( viewport . elementRef . nativeElement , 'scroll' ) ;
711
705
animationFrameScheduler . flush ( ) ;
@@ -766,8 +760,8 @@ class FixedSizeVirtualScroll {
766
760
@Component ( {
767
761
template : `
768
762
<cdk-virtual-scroll-viewport dir="rtl"
769
- [itemSize]="itemSize" [minBufferPx]="minBufferPx" [maxBufferPx]="maxBufferPx"
770
- [orientation]="orientation" [style.height.px]="viewportHeight"
763
+ [itemSize]="itemSize" [minBufferPx]="minBufferPx" [maxBufferPx]="maxBufferPx"
764
+ [orientation]="orientation" [style.height.px]="viewportHeight"
771
765
[style.width.px]="viewportWidth" (scrolledIndexChange)="scrolledToIndex = $event">
772
766
<div class="item"
773
767
*cdkVirtualFor="let item of items; let i = index; trackBy: trackBy; \
0 commit comments