From 2094af15799d32c6e7d2c6defac3d295af5fecb6 Mon Sep 17 00:00:00 2001 From: Vaadin Bot Date: Thu, 5 Dec 2024 14:37:51 +0100 Subject: [PATCH] fix: use Math.round to get correct scroller first index (#8278) (#8283) Co-authored-by: Serhii Kulykov --- .../date-picker/src/vaadin-infinite-scroller.js | 3 ++- packages/date-picker/test/scroller.test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/date-picker/src/vaadin-infinite-scroller.js b/packages/date-picker/src/vaadin-infinite-scroller.js index 1bd340f2a5d..5803a08c3c3 100644 --- a/packages/date-picker/src/vaadin-infinite-scroller.js +++ b/packages/date-picker/src/vaadin-infinite-scroller.js @@ -371,7 +371,8 @@ export class InfiniteScroller extends HTMLElement { /** @private */ _updateClones(viewPortOnly) { - this._firstIndex = ~~((this._buffers[0].translateY - this._initialScroll) / this.itemHeight) + this._initialIndex; + this._firstIndex = + Math.round((this._buffers[0].translateY - this._initialScroll) / this.itemHeight) + this._initialIndex; const scrollerRect = viewPortOnly ? this.$.scroller.getBoundingClientRect() : undefined; this._buffers.forEach((buffer, bufferIndex) => { diff --git a/packages/date-picker/test/scroller.test.js b/packages/date-picker/test/scroller.test.js index 3d5db0122e6..e821d3d2ae7 100644 --- a/packages/date-picker/test/scroller.test.js +++ b/packages/date-picker/test/scroller.test.js @@ -125,3 +125,18 @@ describe('vaadin-infinite-scroller', () => { }); }); }); + +describe('fractional item size', () => { + let scroller; + + beforeEach(async () => { + scroller = fixtureSync(''); + scroller.bufferSize = 80; + scroller.style.setProperty('--vaadin-infinite-scroller-item-height', '30.0001px'); + await activateScroller(scroller); + }); + + it('should be at the position 0', () => { + expect(scroller.position).to.be.closeTo(0, 0.001); + }); +});