From 1033e8425c9d9660a1cab42fc8fb71c0533699e6 Mon Sep 17 00:00:00 2001 From: web-padawan Date: Thu, 5 Dec 2024 12:16:10 +0200 Subject: [PATCH] fix: use Math.round to get correct scroller item count --- .../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 30f2a238ca5..71ffea35521 100644 --- a/packages/date-picker/src/vaadin-infinite-scroller.js +++ b/packages/date-picker/src/vaadin-infinite-scroller.js @@ -391,7 +391,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); + }); +});