Skip to content

Commit 172dca8

Browse files
authored
fix: make scrollToColumn update cell position synchronously (#11291)
1 parent a27b2bb commit 172dca8

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

packages/grid/src/vaadin-grid-scroll-mixin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ export const ScrollMixin = (superClass) =>
206206
}
207207

208208
this._scrollHorizontallyToCell(column._headerCell);
209+
// Update cell position synchronously
210+
this.__updateHorizontalScrollPosition();
209211
// Synchronously update cells when using lazy column rendering
210212
this.__updateColumnsBodyContentHidden();
211213
}

packages/grid/test/scroll-to-column.test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ describe('scroll to column', () => {
5454
return false;
5555
}
5656

57-
const scrollLeft = grid.$.table.scrollLeft;
58-
const clientWidth = grid.$.table.clientWidth;
59-
60-
return (
61-
headerCell.offsetLeft + headerCell.offsetWidth >= scrollLeft && headerCell.offsetLeft <= scrollLeft + clientWidth
62-
);
57+
const bounds = headerCell.getBoundingClientRect();
58+
const centerX = bounds.left + bounds.width / 2;
59+
const centerY = bounds.top + bounds.height / 2;
60+
const cellContent = document.elementFromPoint(centerX, centerY);
61+
return headerCell.querySelector('slot').assignedElements().includes(cellContent);
6362
}
6463

6564
describe('by index', () => {
@@ -216,14 +215,16 @@ describe('scroll to column', () => {
216215
});
217216

218217
it('should not scroll for frozen column (always visible)', () => {
218+
grid.scrollToColumn(9);
219+
expect(isColumnInViewport(columns[9])).to.be.true;
220+
219221
const initialScrollLeft = grid.$.table.scrollLeft;
220222
grid.scrollToColumn(columns[0]);
221223
expect(grid.$.table.scrollLeft).to.equal(initialScrollLeft);
222224
});
223225

224-
it('should scroll non-frozen column into view', async () => {
226+
it('should scroll non-frozen column into view', () => {
225227
grid.scrollToColumn(9);
226-
await nextFrame();
227228
expect(isColumnInViewport(columns[9])).to.be.true;
228229

229230
// Scroll back to first non-frozen

0 commit comments

Comments
 (0)