From 41d25faccc5440327a8abd7eeed6901796980dba Mon Sep 17 00:00:00 2001 From: Robert Messerle Date: Mon, 7 Dec 2015 16:26:41 -0800 Subject: [PATCH] fix(virtualRepeat): sets initial size for virtual repeat when the first results require shrinking closes #5826 --- src/components/virtualRepeat/virtual-repeater.js | 3 ++- .../virtualRepeat/virtual-repeater.spec.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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)