Skip to content

Commit 9820b38

Browse files
刘欢claude
andcommitted
fix: simplify offset handling - scrollIntoView first then add offset
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d31bfef commit 9820b38

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

src/Table.tsx

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -365,39 +365,7 @@ const Table = <RecordType extends DefaultRecordType>(
365365
targetElement.scrollIntoView({ block: align });
366366
if (offset) {
367367
const container = scrollBodyRef.current;
368-
const elementTop = (targetElement as HTMLElement).offsetTop;
369-
const elementHeight = (targetElement as HTMLElement).offsetHeight;
370-
const containerHeight = container.clientHeight;
371-
const elementBottom = elementTop + elementHeight;
372-
let targetTop: number;
373-
switch (align) {
374-
case 'nearest': {
375-
const currentTop = container.scrollTop;
376-
const viewportBottom = currentTop + containerHeight;
377-
const targetWithOffset = elementTop + offset;
378-
const targetBottomWithOffset = elementBottom + offset;
379-
380-
if (targetWithOffset < currentTop) {
381-
targetTop = targetWithOffset;
382-
} else if (targetBottomWithOffset > viewportBottom) {
383-
targetTop = targetBottomWithOffset - containerHeight;
384-
} else {
385-
targetTop = currentTop;
386-
}
387-
break;
388-
}
389-
case 'end':
390-
targetTop = elementBottom - containerHeight + offset;
391-
break;
392-
case 'center':
393-
targetTop = elementTop - (containerHeight - elementHeight) / 2 + offset;
394-
break;
395-
case 'start':
396-
default:
397-
targetTop = elementTop + offset;
398-
}
399-
400-
container.scrollTo({ top: targetTop });
368+
container.scrollTo({ top: container.scrollTop + offset });
401369
}
402370
}
403371
}

0 commit comments

Comments
 (0)