diff --git a/src/components/virtualRepeat/virtual-repeater.js b/src/components/virtualRepeat/virtual-repeater.js index 11c83c53a77..2f0219f2382 100644 --- a/src/components/virtualRepeat/virtual-repeater.js +++ b/src/components/virtualRepeat/virtual-repeater.js @@ -243,7 +243,8 @@ VirtualRepeatContainerController.prototype.sizeScroller_ = function(size) { VirtualRepeatContainerController.prototype.autoShrink_ = function(size) { var shrinkSize = Math.max(size, this.autoShrinkMin * this.repeater.getItemSize()); if (this.autoShrink && shrinkSize !== this.size) { - if (shrinkSize < (this.originalSize || this.size)) { + var currentSize = this.originalSize || this.size; + if (!currentSize || shrinkSize < currentSize) { if (!this.originalSize) { this.originalSize = this.size; } diff --git a/src/components/virtualRepeat/virtual-repeater.spec.js b/src/components/virtualRepeat/virtual-repeater.spec.js index b483f578397..617e64d6ef4 100644 --- a/src/components/virtualRepeat/virtual-repeater.spec.js +++ b/src/components/virtualRepeat/virtual-repeater.spec.js @@ -558,6 +558,21 @@ describe('', function() { expect(offsetter.children().length).toBe(43); }); + it('should shrink when initial results require shrinking', inject(function() { + scope.items = [ + { value: 'alabama', display: 'Alabama' }, + { value: 'alaska', display: 'Alaska' }, + { value: 'arizona', display: 'Arizona' } + ]; + createRepeater(); + var controller = component.controller('mdVirtualRepeatContainer'); + controller.autoShrink = true; + controller.autoShrink_(200); + + expect(component[0].getBoundingClientRect().height).toBe(200); + expect(offsetter.children().length).toBe(3); + })); + /** * Facade to access transform properly even when jQuery is used; * since jQuery's css function is obtaining the computed style (not wanted)