Skip to content

Commit

Permalink
Fix #304
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia committed Aug 25, 2016
1 parent 9de0830 commit db89558
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 5 additions & 6 deletions iron-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -1453,9 +1453,11 @@
if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) {
return;
}

Polymer.dom.flush();

// Items should have been rendered prior scrolling to an index.
if (!this._itemsRendered) {
return;
}
idx = Math.min(Math.max(idx, 0), this._virtualCount-1);
// update the virtual start only when needed
if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) {
Expand All @@ -1467,16 +1469,13 @@
this._assignModels();
// measure the new sizes
this._updateMetrics();

// estimate new physical offset
var estPhysicalTop = Math.floor(this._virtualStart / this._itemsPerRow) * this._physicalAverage;
this._physicalTop = estPhysicalTop;
this._physicalTop = Math.floor(this._virtualStart / this._itemsPerRow) * this._physicalAverage;

var currentTopItem = this._physicalStart;
var currentVirtualItem = this._virtualStart;
var targetOffsetTop = 0;
var hiddenContentSize = this._hiddenContentSize;

// scroll to the item as much as we can
while (currentVirtualItem < idx && targetOffsetTop <= hiddenContentSize) {
targetOffsetTop = targetOffsetTop + this._getPhysicalSizeIncrement(currentTopItem);
Expand Down
9 changes: 9 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@
}, 100);
});

test('scroll to index while not attached', function() {
var tmpList = document.createElement('iron-list');
Polymer.dom(tmpList).appendChild(document.createElement('template'));
tmpList.items = buildDataSet(100);
assert.equal(tmpList._virtualStart, 0);
tmpList.scrollToIndex(50);
assert.equal(tmpList._virtualStart, 0);
});

test('scroll to item', function(done) {
list.items = buildDataSet(100);

Expand Down

0 comments on commit db89558

Please sign in to comment.