@@ -71,7 +71,17 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
71
71
private _renderedRangeSubject = new Subject < ListRange > ( ) ;
72
72
73
73
/** The direction the viewport scrolls. */
74
- @Input ( ) orientation : 'horizontal' | 'vertical' = 'vertical' ;
74
+ @Input ( )
75
+ get orientation ( ) {
76
+ return this . _orientation ;
77
+ }
78
+ set orientation ( orientation : 'horizontal' | 'vertical' ) {
79
+ if ( this . _orientation !== orientation ) {
80
+ this . _orientation = orientation ;
81
+ this . _calculateSpacerSize ( ) ;
82
+ }
83
+ }
84
+ private _orientation : 'horizontal' | 'vertical' = 'vertical' ;
75
85
76
86
// Note: we don't use the typical EventEmitter here because we need to subscribe to the scroll
77
87
// strategy lazily (i.e. only if the user is actually listening to the events). We do this because
@@ -92,7 +102,13 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
92
102
/**
93
103
* The total size of all content (in pixels), including content that is not currently rendered.
94
104
*/
95
- _totalContentSize = 0 ;
105
+ private _totalContentSize = 0 ;
106
+
107
+ /** A string representing the `style.width` property value to be used for the spacer element. */
108
+ _totalContentWidth = '' ;
109
+
110
+ /** A string representing the `style.height` property value to be used for the spacer element. */
111
+ _totalContentHeight = '' ;
96
112
97
113
/**
98
114
* The CSS transform applied to the rendered subset of items so that they appear within the bounds
@@ -232,6 +248,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
232
248
setTotalContentSize ( size : number ) {
233
249
if ( this . _totalContentSize !== size ) {
234
250
this . _totalContentSize = size ;
251
+ this . _calculateSpacerSize ( ) ;
235
252
this . _markChangeDetectionNeeded ( ) ;
236
253
}
237
254
}
@@ -390,4 +407,12 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
390
407
fn ( ) ;
391
408
}
392
409
}
410
+
411
+ /** Calculates the `style.width` and `style.height` for the spacer element. */
412
+ private _calculateSpacerSize ( ) {
413
+ this . _totalContentHeight =
414
+ this . orientation === 'horizontal' ? '' : `${ this . _totalContentSize } px` ;
415
+ this . _totalContentWidth =
416
+ this . orientation === 'horizontal' ? `${ this . _totalContentSize } px` : '' ;
417
+ }
393
418
}
0 commit comments