@@ -412,12 +412,46 @@ describe('CdkVirtualScrollViewport', () => {
412
412
fixture . detectChanges ( ) ;
413
413
flush ( ) ;
414
414
415
- triggerScroll ( viewport ) ;
415
+ expect ( viewport . getOffsetToRenderedContentStart ( ) )
416
+ . toBe ( testComponent . itemSize , 'should be scrolled to bottom of 5 item list' ) ;
417
+ } ) ) ;
418
+
419
+ it ( 'should handle dynamic item array with dynamic buffer' , fakeAsync ( ( ) => {
420
+ finishInit ( fixture ) ;
421
+ triggerScroll ( viewport , testComponent . itemSize * 6 ) ;
416
422
fixture . detectChanges ( ) ;
417
423
flush ( ) ;
418
424
419
425
expect ( viewport . getOffsetToRenderedContentStart ( ) )
420
- . toBe ( testComponent . itemSize , 'should be scrolled to bottom of 5 item list' ) ;
426
+ . toBe ( testComponent . itemSize * 6 , 'should be scrolled to bottom of 10 item list' ) ;
427
+
428
+ testComponent . items = Array ( 5 ) . fill ( 0 ) ;
429
+ testComponent . minBufferPx = testComponent . itemSize ;
430
+ testComponent . maxBufferPx = testComponent . itemSize ;
431
+
432
+ fixture . detectChanges ( ) ;
433
+ flush ( ) ;
434
+
435
+ expect ( viewport . getOffsetToRenderedContentStart ( ) )
436
+ . toBe ( 0 , 'should render from first item' ) ;
437
+ } ) ) ;
438
+
439
+ it ( 'should handle dynamic item array keeping position when possibile' , fakeAsync ( ( ) => {
440
+ testComponent . items = Array ( 100 ) . fill ( 0 ) ;
441
+ finishInit ( fixture ) ;
442
+ triggerScroll ( viewport , testComponent . itemSize * 50 ) ;
443
+ fixture . detectChanges ( ) ;
444
+ flush ( ) ;
445
+
446
+ expect ( viewport . getOffsetToRenderedContentStart ( ) )
447
+ . toBe ( testComponent . itemSize * 50 , 'should be scrolled to index 50 item list' ) ;
448
+
449
+ testComponent . items = Array ( 54 ) . fill ( 0 ) ;
450
+ fixture . detectChanges ( ) ;
451
+ flush ( ) ;
452
+
453
+ expect ( viewport . getOffsetToRenderedContentStart ( ) )
454
+ . toBe ( testComponent . itemSize * 50 , 'should be kept the scroll position' ) ;
421
455
} ) ) ;
422
456
423
457
it ( 'should update viewport as user scrolls right in horizontal mode' , fakeAsync ( ( ) => {
@@ -900,6 +934,15 @@ function triggerScroll(viewport: CdkVirtualScrollViewport, offset?: number) {
900
934
.cdk-virtual-scroll-orientation-horizontal .cdk-virtual-scroll-content-wrapper {
901
935
flex-direction: row;
902
936
}
937
+
938
+ .cdk-virtual-scroll-viewport {
939
+ background-color: #f5f5f5;
940
+ }
941
+
942
+ .item {
943
+ box-sizing: border-box;
944
+ border: 1px dashed #ccc;
945
+ }
903
946
` ] ,
904
947
encapsulation : ViewEncapsulation . None ,
905
948
} )
@@ -952,6 +995,15 @@ class FixedSizeVirtualScroll {
952
995
.cdk-virtual-scroll-orientation-horizontal .cdk-virtual-scroll-content-wrapper {
953
996
flex-direction: row;
954
997
}
998
+
999
+ .cdk-virtual-scroll-viewport {
1000
+ background-color: #f5f5f5;
1001
+ }
1002
+
1003
+ .item {
1004
+ box-sizing: border-box;
1005
+ border: 1px dashed #ccc;
1006
+ }
955
1007
` ] ,
956
1008
encapsulation : ViewEncapsulation . None ,
957
1009
} )
@@ -982,9 +1034,19 @@ class FixedSizeVirtualScrollWithRtlDirection {
982
1034
@Component ( {
983
1035
template : `
984
1036
<cdk-virtual-scroll-viewport>
985
- <div *cdkVirtualFor="let item of items">{{item}}</div>
1037
+ <div class="item" *cdkVirtualFor="let item of items">{{item}}</div>
986
1038
</cdk-virtual-scroll-viewport>
987
- `
1039
+ ` ,
1040
+ styles : [ `
1041
+ .cdk-virtual-scroll-viewport {
1042
+ background-color: #f5f5f5;
1043
+ }
1044
+
1045
+ .item {
1046
+ box-sizing: border-box;
1047
+ border: 1px dashed #ccc;
1048
+ }
1049
+ ` ]
988
1050
} )
989
1051
class VirtualScrollWithNoStrategy {
990
1052
items = [ ] ;
@@ -1013,11 +1075,14 @@ class InjectsViewContainer {
1013
1075
.cdk-virtual-scroll-viewport {
1014
1076
width: 200px;
1015
1077
height: 200px;
1078
+ background-color: #f5f5f5;
1016
1079
}
1017
1080
1018
1081
.item {
1019
1082
width: 100%;
1020
1083
height: 50px;
1084
+ box-sizing: border-box;
1085
+ border: 1px dashed #ccc;
1021
1086
}
1022
1087
` ] ,
1023
1088
encapsulation : ViewEncapsulation . None
0 commit comments