Skip to content

Commit 011f5f1

Browse files
committed
chore: align with virtual
1 parent 032686b commit 011f5f1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/VirtualTable/BodyGrid.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,18 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
7878
React.useImperativeHandle(ref, () => {
7979
const obj = {
8080
scrollTo: (config: ScrollConfig) => {
81-
listRef.current?.scrollTo(config);
81+
const { offset, ...restConfig } = config;
82+
83+
// If offset is provided, force align to 'top' for consistent behavior
84+
if (offset) {
85+
listRef.current?.scrollTo({
86+
...restConfig,
87+
offset,
88+
align: 'top',
89+
});
90+
} else {
91+
listRef.current?.scrollTo(config);
92+
}
8293
},
8394
nativeElement: listRef.current?.nativeElement,
8495
} as unknown as GridRef;

tests/Virtual.spec.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ describe('Table.Virtual', () => {
383383
expect(global.scrollToConfig).toEqual({
384384
index: 50,
385385
offset: 20,
386+
align: 'top',
386387
});
387388

388389
// Test key with offset
@@ -396,6 +397,7 @@ describe('Table.Virtual', () => {
396397
expect(global.scrollToConfig).toEqual({
397398
key: '25',
398399
offset: -10,
400+
align: 'top',
399401
});
400402

401403
// Test top with offset (offset should be passed to virtual list)
@@ -409,6 +411,7 @@ describe('Table.Virtual', () => {
409411
expect(global.scrollToConfig).toEqual({
410412
top: 100,
411413
offset: 30,
414+
align: 'top',
412415
});
413416
});
414417

0 commit comments

Comments
 (0)