From 39af300422370995f6f96460f4bbb08144ee4e06 Mon Sep 17 00:00:00 2001 From: Serhii Kulykov Date: Thu, 5 Dec 2024 15:03:23 +0200 Subject: [PATCH] fix: use Math.round to get correct scroller first index (#8278) --- .../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 0dc62272cc..d04f40c10a 100644 --- a/packages/date-picker/src/vaadin-infinite-scroller.js +++ b/packages/date-picker/src/vaadin-infinite-scroller.js @@ -376,7 +376,8 @@ class InfiniteScroller extends PolymerElement { /** @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 d808674aa1..0cbea53350 100644 --- a/packages/date-picker/test/scroller.test.js +++ b/packages/date-picker/test/scroller.test.js @@ -118,3 +118,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); + }); +});