@@ -71,7 +71,17 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
7171 private _renderedRangeSubject = new Subject < ListRange > ( ) ;
7272
7373 /** 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' ;
7585
7686 // Note: we don't use the typical EventEmitter here because we need to subscribe to the scroll
7787 // strategy lazily (i.e. only if the user is actually listening to the events). We do this because
@@ -89,17 +99,17 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
8999 /** A stream that emits whenever the rendered range changes. */
90100 renderedRangeStream : Observable < ListRange > = this . _renderedRangeSubject . asObservable ( ) ;
91101
92- /**
93- * The transform used to scale the spacer to the same size as all content, including content that
94- * is not currently rendered.
95- */
96- _totalContentSizeTransform = '' ;
97-
98102 /**
99103 * The total size of all content (in pixels), including content that is not currently rendered.
100104 */
101105 private _totalContentSize = 0 ;
102106
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 = '' ;
112+
103113 /**
104114 * The CSS transform applied to the rendered subset of items so that they appear within the bounds
105115 * of the visible viewport.
@@ -238,8 +248,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
238248 setTotalContentSize ( size : number ) {
239249 if ( this . _totalContentSize !== size ) {
240250 this . _totalContentSize = size ;
241- const axis = this . orientation == 'horizontal' ? 'X' : 'Y' ;
242- this . _totalContentSizeTransform = `scale${ axis } (${ this . _totalContentSize } )` ;
251+ this . _calculateSpacerSize ( ) ;
243252 this . _markChangeDetectionNeeded ( ) ;
244253 }
245254 }
@@ -398,4 +407,12 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
398407 fn ( ) ;
399408 }
400409 }
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+ }
401418}
0 commit comments