Skip to content

Commit

Permalink
Add test and fix scroll to
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-fix committed Oct 27, 2020
1 parent 98deb3f commit 7bd52f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/vaadin-grid-scroller.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
scrollToIndex(index) {
this._warnPrivateAPIAccess('scrollToIndex');

if (index > this._physicalCount) {
this._increasePoolIfNeeded(0);
this._debounceIncreasePool && this._debounceIncreasePool.flush();
}

this._scrollingToIndex = true;
index = Math.min(Math.max(index, 0), this._effectiveSize - 1);
this.$.table.scrollTop = index / this._effectiveSize * (this.$.table.scrollHeight - this.$.table.offsetHeight);
Expand Down
27 changes: 27 additions & 0 deletions test/scroll-to-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,33 @@

});

describe('Added item', () => {
let grid, scroller, data;

beforeEach(() => {
grid = fixture('large');
data = Array(...new Array(10)).map((_, i) => {
return {'index': i};
});

grid.size = 10;
grid.dataProvider = function(params, callback) {
callback(data);
};

flushGrid(grid);
});

it('should not reassign the first item on scrollToIndex', () => {
const newExpectedSize = grid.size + 1;
grid.size = newExpectedSize;
data.push({'index': 11});
grid.scrollToIndex(grid.items.length);

expect(grid.$.items.children[0]._item.index).to.equal(0);
});
});

});
</script>

Expand Down

0 comments on commit 7bd52f3

Please sign in to comment.