Skip to content

Commit 5df5b21

Browse files
author
saeed
committed
change stickyScrollBar onMouseMove
1 parent e476e82 commit 5df5b21

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
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: 24 additions & 12 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,18 +75,29 @@ 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+
if(direction === "ltr"){
79+
if (left <= 0) {
80+
left = 0;
81+
}
82+
if (left + scrollBarWidth >= bodyWidth) {
83+
left = bodyWidth - scrollBarWidth;
84+
}
85+
onScroll({
86+
scrollLeft: left / bodyWidth * (bodyScrollWidth + 2)
87+
});
88+
refState.current.x = event.pageX;
89+
}else{
90+
if (left > 0) {
91+
left = 0;
92+
}
93+
if (Math.abs(left) + Math.abs(scrollBarWidth) < bodyWidth) {
94+
onScroll({
95+
scrollLeft: left / bodyWidth * (bodyScrollWidth + 2)
96+
});
97+
refState.current.x = event.pageX;
98+
}
8399
}
84100

85-
onScroll({
86-
scrollLeft: (left / bodyWidth) * (bodyScrollWidth + 2),
87-
});
88-
89101
refState.current.x = event.pageX;
90102
};
91103

0 commit comments

Comments
 (0)