Skip to content

Commit

Permalink
fix: use Math.round to get correct scroller first index (#8278)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored and vaadin-bot committed Dec 5, 2024
1 parent 2d9f7e4 commit c6dffd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/date-picker/src/vaadin-infinite-scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
15 changes: 15 additions & 0 deletions packages/date-picker/test/scroller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,18 @@ describe('vaadin-infinite-scroller', () => {
});
});
});

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

beforeEach(async () => {
scroller = fixtureSync('<vaadin-infinite-scroller></vaadin-infinite-scroller>');
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);
});
});

0 comments on commit c6dffd1

Please sign in to comment.