From 1771b29f94057e635e41b1489e0292ce6706a47c Mon Sep 17 00:00:00 2001 From: Jeremy Elbourn Date: Fri, 4 Dec 2015 11:44:15 -0800 Subject: [PATCH] fix(virtualRepeat): fix sizer not shrinking when items reduce in number. Fixes #4435 --- .../virtualRepeat/virtual-repeater.js | 5 ++-- .../virtualRepeat/virtual-repeater.spec.js | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/components/virtualRepeat/virtual-repeater.js b/src/components/virtualRepeat/virtual-repeater.js index a1a02b1c9a6..073a1587021 100644 --- a/src/components/virtualRepeat/virtual-repeater.js +++ b/src/components/virtualRepeat/virtual-repeater.js @@ -206,14 +206,15 @@ VirtualRepeatContainerController.prototype.sizeScroller_ = function(size) { var dimension = this.isHorizontal() ? 'width' : 'height'; var crossDimension = this.isHorizontal() ? 'height' : 'width'; + // Clear any existing dimensions. + this.sizer.innerHTML = ''; + // If the size falls within the browser's maximum explicit size for a single element, we can // set the size and be done. Otherwise, we have to create children that add up the the desired // size. if (size < MAX_ELEMENT_SIZE) { this.sizer.style[dimension] = size + 'px'; } else { - // Clear any existing dimensions. - this.sizer.innerHTML = ''; this.sizer.style[dimension] = 'auto'; this.sizer.style[crossDimension] = 'auto'; diff --git a/src/components/virtualRepeat/virtual-repeater.spec.js b/src/components/virtualRepeat/virtual-repeater.spec.js index b483f578397..69902d03a83 100644 --- a/src/components/virtualRepeat/virtual-repeater.spec.js +++ b/src/components/virtualRepeat/virtual-repeater.spec.js @@ -285,6 +285,30 @@ describe('', function() { } }); + it('should clear scroller if large set of items is filtered to much smaller set', function() { + // Create a much larger number of items than will fit in one maximum element size. + var numItems = 2000000; + createRepeater(); + scope.items = createItems(numItems); + scope.$apply(); + $$rAF.flush(); + + // Expect that the sizer as a whole is still exactly the height it should be. + expect(sizer[0].offsetHeight).toBe(numItems * ITEM_SIZE); + + // Now that the sizer is really big, change the the number of items to be very small. + numItems = 2; + scope.items = createItems(numItems); + scope.$apply(); + $$rAF.flush(); + + // Expect that the sizer as a whole is still exactly the height it should be. + expect(sizer[0].offsetHeight).toBe(numItems * ITEM_SIZE); + + // Expect that the sizer has no children, as all of items fit comfortably in a single element. + expect(sizer[0].children.length).toBe(0); + }); + it('should start at the given scroll position', function() { scope.startIndex = 10; scope.items = createItems(200);