Skip to content

Commit cb61872

Browse files
saeedjafari68saeed
and
saeed
authored
change stickyScrollBar onMouseMove (#1215)
* change stickyScrollBar onMouseMove * resolve review --------- Co-authored-by: saeed <[email protected]>
1 parent e476e82 commit cb61872

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/Table.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ function Table<RecordType extends DefaultRecordType>(
726726
scrollBodyRef={scrollBodyRef}
727727
onScroll={onInternalScroll}
728728
container={container}
729+
direction={direction}
729730
/>
730731
)}
731732
</>

src/stickyScrollBar.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ interface StickyScrollBarProps {
1212
scrollBodyRef: React.RefObject<HTMLDivElement>;
1313
onScroll: (params: { scrollLeft?: number }) => void;
1414
offsetScroll: number;
15-
container: HTMLElement | Window;
15+
container: HTMLElement | Window,
16+
direction: string;
1617
}
1718

1819
const StickyScrollBar: React.ForwardRefRenderFunction<unknown, StickyScrollBarProps> = (
19-
{ scrollBodyRef, onScroll, offsetScroll, container },
20+
{ scrollBodyRef, onScroll, offsetScroll, container, direction },
2021
ref,
2122
) => {
2223
const prefixCls = useContext(TableContext, 'prefixCls');
@@ -74,19 +75,21 @@ const StickyScrollBar: React.ForwardRefRenderFunction<unknown, StickyScrollBarPr
7475
let left: number =
7576
refState.current.x + event.pageX - refState.current.x - refState.current.delta;
7677

77-
if (left <= 0) {
78-
left = 0;
79-
}
80-
81-
if (left + scrollBarWidth >= bodyWidth) {
82-
left = bodyWidth - scrollBarWidth;
78+
const isLTR = direction === "ltr";
79+
// Limit scroll range
80+
left = Math.max(
81+
isLTR ? 0 : -bodyWidth + scrollBarWidth,
82+
Math.min(isLTR ? bodyWidth - scrollBarWidth : 0, left)
83+
);
84+
// Calculate the scroll position and update
85+
const shouldScroll =
86+
isLTR || Math.abs(left) + Math.abs(scrollBarWidth) < bodyWidth;
87+
if (shouldScroll) {
88+
onScroll({
89+
scrollLeft: (left / bodyWidth) * (bodyScrollWidth + 2),
90+
});
91+
refState.current.x = event.pageX;
8392
}
84-
85-
onScroll({
86-
scrollLeft: (left / bodyWidth) * (bodyScrollWidth + 2),
87-
});
88-
89-
refState.current.x = event.pageX;
9093
};
9194

9295
const checkScrollBarVisible = () => {

0 commit comments

Comments
 (0)