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

fix(virtualRepeat): fix sizer not shrinking when items reduce in number. #6087

Merged
merged 1 commit into from
Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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