Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: keep fractional row scroll target",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "biukam.w@gmail.com"
}
36 changes: 36 additions & 0 deletions packages/vtable/__tests__/api/listTable-scrollToRow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// @ts-nocheck
import { ListTable } from '../../src';
import { createDiv } from '../dom';

global.__VERSION__ = 'none';

describe('listTable scrollToRow api', () => {
afterEach(() => {
jest.restoreAllMocks();
document.body.innerHTML = '';
});

test('keeps fractional row target when scrolling with animation', () => {
const container = createDiv();
container.style.position = 'relative';
container.style.width = '400px';
container.style.height = '240px';

const table = new ListTable({
container,
columns: [{ field: 'name', title: 'Name', width: 120 }],
records: Array.from({ length: 20 }, (_, index) => ({ name: `row-${index}` })),
defaultRowHeight: 40
});

const scrollTo = jest.spyOn(table.animationManager, 'scrollTo').mockImplementation(() => undefined);
const setTimeoutSpy = jest.spyOn(globalThis, 'setTimeout').mockImplementation(() => 0 as any);

table.scrollToRow(1.5, { duration: 100, easing: 'linear' });

expect(scrollTo).toHaveBeenCalledWith({ row: 1.5 }, { duration: 100, easing: 'linear' });
expect(setTimeoutSpy).not.toHaveBeenCalled();

table.release();
});
});
15 changes: 9 additions & 6 deletions packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5275,18 +5275,21 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {

// anmiation
scrollToRow(row: number, animationOption?: ITableAnimationOption | boolean) {
const targetRow = Math.min(Math.max(Math.floor(row), 0), this.rowCount - 1);
const targetRow = Math.min(Math.max(row, 0), this.rowCount - 1);
const targetRowInt = Math.floor(targetRow);
this.clearCorrectTimer();
if (!animationOption) {
this.scrollToCell({ row: targetRow });
this._scheduleScrollToRowCorrect(targetRow);
this.scrollToCell({ row: targetRowInt });
this._scheduleScrollToRowCorrect(targetRowInt);
return;
}
const duration = !isBoolean(animationOption) ? animationOption?.duration ?? 3000 : 3000;
this.animationManager.scrollTo({ row: targetRow }, animationOption);
this._scrollToRowCorrectTimer = setTimeout(() => {
this.scrollToRow(targetRow, false);
}, duration);
if (targetRowInt === targetRow) {
this._scrollToRowCorrectTimer = setTimeout(() => {
this.scrollToRow(targetRowInt, false);
}, duration);
}
}
scrollToCol(col: number, animationOption?: ITableAnimationOption | boolean) {
if (!animationOption) {
Expand Down
Loading