Skip to content

Commit

Permalink
fix(virtualRepeat): fix sizer not shrinking when items reduce in number.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed Dec 4, 2015
1 parent 1938945 commit 1771b29
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/virtualRepeat/virtual-repeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
24 changes: 24 additions & 0 deletions src/components/virtualRepeat/virtual-repeater.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,30 @@ describe('<md-virtual-repeat>', 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);
Expand Down

0 comments on commit 1771b29

Please sign in to comment.