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

Commit 6acd1c3

Browse files
Robert Messerlejelbourn
Robert Messerle
authored andcommitted
fix(virtualRepeat): sets initial size for virtual repeat when the first results require shrinking
closes #5826 Closes #6139
1 parent 9d72659 commit 6acd1c3

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/components/virtualRepeat/virtual-repeater.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ VirtualRepeatContainerController.prototype.sizeScroller_ = function(size) {
253253
VirtualRepeatContainerController.prototype.autoShrink_ = function(size) {
254254
var shrinkSize = Math.max(size, this.autoShrinkMin * this.repeater.getItemSize());
255255
if (this.autoShrink && shrinkSize !== this.size) {
256-
if (shrinkSize < (this.originalSize || this.size)) {
256+
var currentSize = this.originalSize || this.size;
257+
if (!currentSize || shrinkSize < currentSize) {
257258
if (!this.originalSize) {
258259
this.originalSize = this.size;
259260
}

src/components/virtualRepeat/virtual-repeater.spec.js

+13-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('<md-virtual-repeat>', function() {
2222
ITEM_SIZE = 10;
2323

2424
beforeEach(inject(function(
25-
_$$rAF_, _$compile_, _$document_, _$mdUtil_, $rootScope, _$timeout_, _$window_, _$material_) {
25+
_$$rAF_, _$compile_, _$document_, _$mdUtil_, $rootScope, _$window_, _$material_) {
2626
repeater = angular.element(REPEATER_HTML);
2727
container = angular.element(CONTAINER_HTML).append(repeater);
2828
component = null;
@@ -31,7 +31,6 @@ describe('<md-virtual-repeat>', function() {
3131
$mdUtil = _$mdUtil_;
3232
$compile = _$compile_;
3333
$document = _$document_;
34-
$timeout = _$timeout_;
3534
$window = _$window_;
3635
scope = $rootScope.$new();
3736
scope.startIndex = 0;
@@ -583,24 +582,20 @@ describe('<md-virtual-repeat>', function() {
583582
expect(offsetter.children().length).toBe(43);
584583
});
585584

586-
it('makes a second attempt to measure the size if it starts out at 0',
587-
function() {
588-
// Create the repeater before appending it to the body.
589-
scope.items = createItems(100);
590-
component = $compile(container)(scope);
591-
$material.flushOutstandingAnimations();
592-
angular.element($document[0].body).append(container);
593-
offsetter = angular.element(component[0].querySelector('.md-virtual-repeat-offsetter'));
585+
it('should shrink when initial results require shrinking', inject(function() {
586+
scope.items = [
587+
{ value: 'alabama', display: 'Alabama' },
588+
{ value: 'alaska', display: 'Alaska' },
589+
{ value: 'arizona', display: 'Arizona' }
590+
];
591+
createRepeater();
592+
var controller = component.controller('mdVirtualRepeatContainer');
593+
controller.autoShrink = true;
594+
controller.autoShrink_(200);
594595

595-
// Expect 3 children (0 + 3 extra).
596+
expect(component[0].getBoundingClientRect().height).toBe(200);
596597
expect(offsetter.children().length).toBe(3);
597-
598-
// Expect it to remeasure using debounce.
599-
$timeout.flush();
600-
601-
// Expect 13 children (10 + 3 extra).
602-
expect(offsetter.children().length).toBe(13);
603-
});
598+
}));
604599

605600
/**
606601
* Facade to access transform properly even when jQuery is used;

0 commit comments

Comments
 (0)