Skip to content

Commit a150b55

Browse files
authored
fix: defer scrollToIndex calls until columnTree is available (#2254)
1 parent d35d50b commit a150b55

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/vaadin-grid-data-provider-mixin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@
509509

510510
scrollToIndex(index) {
511511
super.scrollToIndex(index);
512-
if (!isNaN(index) && (this._cache.isLoading() || !this.clientHeight)) {
512+
if (!isNaN(index) && (this._cache.isLoading() || !this.clientHeight || !this._columnTree)) {
513513
this.__pendingScrollToIndex = index;
514514
}
515515
}

test/scroll-to-index.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
</vaadin-grid>
4949
</template>
5050
</test-fixture>
51+
5152
<script>
5253
describe('Scroll to index', () => {
5354

@@ -318,7 +319,23 @@
318319
grid.scrollToIndex(14);
319320
});
320321
});
322+
323+
describe('before grid is fully initialized', () => {
324+
let grid;
325+
326+
beforeEach((done) => {
327+
grid = fixture('small');
328+
grid.items = Array.from({length: 100}, (_, index) => `Item ${index}`);
329+
grid.scrollToIndex(50);
330+
flushGrid(grid);
331+
animationFrameFlush(done);
332+
});
333+
334+
it('should scroll to index after items are rendered', () => {
335+
expect(grid._firstVisibleIndex).to.equal(50);
336+
});
337+
});
321338
</script>
322339
</body>
323340

324-
</html>
341+
</html>

0 commit comments

Comments
 (0)