Skip to content

Commit 2db0f9d

Browse files
author
saeed
committed
resolve review
1 parent 5df5b21 commit 2db0f9d

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/stickyScrollBar.tsx

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,21 @@ const StickyScrollBar: React.ForwardRefRenderFunction<unknown, StickyScrollBarPr
7575
let left: number =
7676
refState.current.x + event.pageX - refState.current.x - refState.current.delta;
7777

78-
if(direction === "ltr"){
79-
if (left <= 0) {
80-
left = 0;
81-
}
82-
if (left + scrollBarWidth >= bodyWidth) {
83-
left = bodyWidth - scrollBarWidth;
84-
}
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) {
8588
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-
}
89+
scrollLeft: (left / bodyWidth) * (bodyScrollWidth + 2),
90+
});
91+
refState.current.x = event.pageX;
9992
}
100-
101-
refState.current.x = event.pageX;
10293
};
10394

10495
const checkScrollBarVisible = () => {

0 commit comments

Comments
 (0)