diff --git a/src/Table.tsx b/src/Table.tsx index a1db3de5b..5b9ec0898 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -726,6 +726,7 @@ function Table( scrollBodyRef={scrollBodyRef} onScroll={onInternalScroll} container={container} + direction={direction} /> )} diff --git a/src/stickyScrollBar.tsx b/src/stickyScrollBar.tsx index 812bc617c..010e2dfee 100644 --- a/src/stickyScrollBar.tsx +++ b/src/stickyScrollBar.tsx @@ -12,11 +12,12 @@ interface StickyScrollBarProps { scrollBodyRef: React.RefObject; onScroll: (params: { scrollLeft?: number }) => void; offsetScroll: number; - container: HTMLElement | Window; + container: HTMLElement | Window, + direction: string; } const StickyScrollBar: React.ForwardRefRenderFunction = ( - { scrollBodyRef, onScroll, offsetScroll, container }, + { scrollBodyRef, onScroll, offsetScroll, container, direction }, ref, ) => { const prefixCls = useContext(TableContext, 'prefixCls'); @@ -74,19 +75,21 @@ const StickyScrollBar: React.ForwardRefRenderFunction= bodyWidth) { - left = bodyWidth - scrollBarWidth; + const isLTR = direction === "ltr"; + // Limit scroll range + left = Math.max( + isLTR ? 0 : -bodyWidth + scrollBarWidth, + Math.min(isLTR ? bodyWidth - scrollBarWidth : 0, left) + ); + // Calculate the scroll position and update + const shouldScroll = + isLTR || Math.abs(left) + Math.abs(scrollBarWidth) < bodyWidth; + if (shouldScroll) { + onScroll({ + scrollLeft: (left / bodyWidth) * (bodyScrollWidth + 2), + }); + refState.current.x = event.pageX; } - - onScroll({ - scrollLeft: (left / bodyWidth) * (bodyScrollWidth + 2), - }); - - refState.current.x = event.pageX; }; const checkScrollBarVisible = () => {