@@ -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
@@ -89,17 +99,17 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
89
99
/** A stream that emits whenever the rendered range changes. */
90
100
renderedRangeStream : Observable < ListRange > = this . _renderedRangeSubject . asObservable ( ) ;
91
101
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
-
98
102
/**
99
103
* The total size of all content (in pixels), including content that is not currently rendered.
100
104
*/
101
105
private _totalContentSize = 0 ;
102
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 = '' ;
112
+
103
113
/**
104
114
* The CSS transform applied to the rendered subset of items so that they appear within the bounds
105
115
* of the visible viewport.
@@ -238,8 +248,7 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
238
248
setTotalContentSize ( size : number ) {
239
249
if ( this . _totalContentSize !== size ) {
240
250
this . _totalContentSize = size ;
241
- const axis = this . orientation == 'horizontal' ? 'X' : 'Y' ;
242
- this . _totalContentSizeTransform = `scale${ axis } (${ this . _totalContentSize } )` ;
251
+ this . _calculateSpacerSize ( ) ;
243
252
this . _markChangeDetectionNeeded ( ) ;
244
253
}
245
254
}
@@ -398,4 +407,12 @@ export class CdkVirtualScrollViewport extends CdkScrollable implements OnInit, O
398
407
fn ( ) ;
399
408
}
400
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
+ }
401
418
}
0 commit comments