Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 1771b29

Browse files
committed
fix(virtualRepeat): fix sizer not shrinking when items reduce in number.
Fixes #4435
1 parent 1938945 commit 1771b29

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/components/virtualRepeat/virtual-repeater.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,15 @@ VirtualRepeatContainerController.prototype.sizeScroller_ = function(size) {
206206
var dimension = this.isHorizontal() ? 'width' : 'height';
207207
var crossDimension = this.isHorizontal() ? 'height' : 'width';
208208

209+
// Clear any existing dimensions.
210+
this.sizer.innerHTML = '';
211+
209212
// If the size falls within the browser's maximum explicit size for a single element, we can
210213
// set the size and be done. Otherwise, we have to create children that add up the the desired
211214
// size.
212215
if (size < MAX_ELEMENT_SIZE) {
213216
this.sizer.style[dimension] = size + 'px';
214217
} else {
215-
// Clear any existing dimensions.
216-
this.sizer.innerHTML = '';
217218
this.sizer.style[dimension] = 'auto';
218219
this.sizer.style[crossDimension] = 'auto';
219220

src/components/virtualRepeat/virtual-repeater.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,30 @@ describe('<md-virtual-repeat>', function() {
285285
}
286286
});
287287

288+
it('should clear scroller if large set of items is filtered to much smaller set', function() {
289+
// Create a much larger number of items than will fit in one maximum element size.
290+
var numItems = 2000000;
291+
createRepeater();
292+
scope.items = createItems(numItems);
293+
scope.$apply();
294+
$$rAF.flush();
295+
296+
// Expect that the sizer as a whole is still exactly the height it should be.
297+
expect(sizer[0].offsetHeight).toBe(numItems * ITEM_SIZE);
298+
299+
// Now that the sizer is really big, change the the number of items to be very small.
300+
numItems = 2;
301+
scope.items = createItems(numItems);
302+
scope.$apply();
303+
$$rAF.flush();
304+
305+
// Expect that the sizer as a whole is still exactly the height it should be.
306+
expect(sizer[0].offsetHeight).toBe(numItems * ITEM_SIZE);
307+
308+
// Expect that the sizer has no children, as all of items fit comfortably in a single element.
309+
expect(sizer[0].children.length).toBe(0);
310+
});
311+
288312
it('should start at the given scroll position', function() {
289313
scope.startIndex = 10;
290314
scope.items = createItems(200);

0 commit comments

Comments
 (0)