Skip to content

Commit

Permalink
fix: use Math.round to get correct scroller first index (#8278) (#8284)
Browse files Browse the repository at this point in the history
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
  • Loading branch information
vaadin-bot and web-padawan authored Dec 6, 2024
1 parent e7ca3ff commit e1a0e99
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/date-picker/src/vaadin-infinite-scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ class InfiniteScroller extends PolymerElement {

/** @private */
_updateClones(viewPortOnly) {
this._firstIndex = ~~((this._buffers[0].translateY - this._initialScroll) / this.itemHeight) + this._initialIndex;
const itemCount = (this._buffers[0].translateY - this._initialScroll) / this.itemHeight;
if (isNaN(itemCount)) {
return;
}
this._firstIndex = Math.round(itemCount) + this._initialIndex;

const scrollerRect = viewPortOnly ? this.$.scroller.getBoundingClientRect() : undefined;
this._buffers.forEach((buffer, bufferIndex) => {
Expand Down
20 changes: 20 additions & 0 deletions packages/date-picker/test/scroller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,23 @@ describe('vaadin-infinite-scroller', () => {
});
});
});

describe('fractional item size', () => {
let scroller;

beforeEach(async () => {
scroller = fixtureSync(`
<vaadin-infinite-scroller buffer-size="80">
<template>
<div>[[index]]</div>
</template>
</vaadin-infinite-scroller>
`);
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);
});
});

0 comments on commit e1a0e99

Please sign in to comment.