Skip to content

Commit af98647

Browse files
committed
fix: stickyScrollBar in RTL mode
1 parent d7ccfb4 commit af98647

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/stickyScrollBar.tsx

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

@@ -75,15 +75,14 @@ const StickyScrollBar: React.ForwardRefRenderFunction<unknown, StickyScrollBarPr
7575
let left: number =
7676
refState.current.x + event.pageX - refState.current.x - refState.current.delta;
7777

78-
const isLTR = direction === "ltr";
78+
const isRTL = direction === 'rtl';
7979
// Limit scroll range
8080
left = Math.max(
81-
isLTR ? 0 : -bodyWidth + scrollBarWidth,
82-
Math.min(isLTR ? bodyWidth - scrollBarWidth : 0, left)
81+
isRTL ? scrollBarWidth - bodyWidth : 0,
82+
Math.min(isRTL ? 0 : bodyWidth - scrollBarWidth, left),
8383
);
8484
// Calculate the scroll position and update
85-
const shouldScroll =
86-
isLTR || Math.abs(left) + Math.abs(scrollBarWidth) < bodyWidth;
85+
const shouldScroll = !isRTL || Math.abs(left) + Math.abs(scrollBarWidth) < bodyWidth;
8786
if (shouldScroll) {
8887
onScroll({
8988
scrollLeft: (left / bodyWidth) * (bodyScrollWidth + 2),

0 commit comments

Comments
 (0)