From 5df5b21fac79a4ecab11c8d95228682bdef7083f Mon Sep 17 00:00:00 2001 From: saeed Date: Sun, 29 Dec 2024 22:49:50 +0330 Subject: [PATCH 1/2] change stickyScrollBar onMouseMove --- src/Table.tsx | 1 + src/stickyScrollBar.tsx | 36 ++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) 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..8eabfed8b 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,18 +75,29 @@ const StickyScrollBar: React.ForwardRefRenderFunction= bodyWidth) { - left = bodyWidth - scrollBarWidth; + if(direction === "ltr"){ + if (left <= 0) { + left = 0; + } + if (left + scrollBarWidth >= bodyWidth) { + left = bodyWidth - scrollBarWidth; + } + onScroll({ + scrollLeft: left / bodyWidth * (bodyScrollWidth + 2) + }); + refState.current.x = event.pageX; + }else{ + if (left > 0) { + left = 0; + } + if (Math.abs(left) + Math.abs(scrollBarWidth) < bodyWidth) { + onScroll({ + scrollLeft: left / bodyWidth * (bodyScrollWidth + 2) + }); + refState.current.x = event.pageX; + } } - onScroll({ - scrollLeft: (left / bodyWidth) * (bodyScrollWidth + 2), - }); - refState.current.x = event.pageX; }; From 2db0f9d220acd8b87ec3cef1e25c3d341e000ad6 Mon Sep 17 00:00:00 2001 From: saeed Date: Mon, 30 Dec 2024 10:37:00 +0330 Subject: [PATCH 2/2] resolve review --- src/stickyScrollBar.tsx | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/stickyScrollBar.tsx b/src/stickyScrollBar.tsx index 8eabfed8b..010e2dfee 100644 --- a/src/stickyScrollBar.tsx +++ b/src/stickyScrollBar.tsx @@ -75,30 +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; - }else{ - if (left > 0) { - left = 0; - } - if (Math.abs(left) + Math.abs(scrollBarWidth) < bodyWidth) { - onScroll({ - scrollLeft: left / bodyWidth * (bodyScrollWidth + 2) - }); - refState.current.x = event.pageX; - } + scrollLeft: (left / bodyWidth) * (bodyScrollWidth + 2), + }); + refState.current.x = event.pageX; } - - refState.current.x = event.pageX; }; const checkScrollBarVisible = () => {