Skip to content

Commit

Permalink
Fix RTL handling
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Oct 1, 2024
1 parent 489b638 commit 89e5913
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/mui-base/src/ScrollArea/Root/ScrollAreaRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const ScrollAreaRoot = React.forwardRef(function ScrollAreaRoot(
className,
ownerState,
extraProps: mergeReactProps(otherProps, {
dir,
onMouseEnter() {
setHovering(true);
},
Expand Down
15 changes: 13 additions & 2 deletions packages/mui-base/src/ScrollArea/Scrollbar/ScrollAreaScrollbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ const ScrollAreaScrollbar = React.forwardRef(function ScrollAreaScrollbar(
viewportRef.current.scrollTop = newScrollTop;
}

// Handle X-axis (horizontal) scroll
if (thumbXRef.current && scrollbarXRef.current && orientation === 'horizontal') {
const thumbWidth = thumbXRef.current.offsetWidth;
const trackRectX = scrollbarXRef.current.getBoundingClientRect();
Expand All @@ -141,7 +140,19 @@ const ScrollAreaScrollbar = React.forwardRef(function ScrollAreaScrollbar(

const maxThumbOffsetX = scrollbarXRef.current.offsetWidth - thumbWidth;
const scrollRatioX = clickX / maxThumbOffsetX;
const newScrollLeft = scrollRatioX * (scrollableContentWidth - viewportWidth);

let newScrollLeft: number;
if (dir === 'rtl') {
// In RTL, we need to invert the scroll direction
newScrollLeft = (1 - scrollRatioX) * (scrollableContentWidth - viewportWidth);

// Adjust for browsers that use negative scrollLeft in RTL
if (viewportRef.current.scrollLeft <= 0) {
newScrollLeft = -newScrollLeft;
}
} else {
newScrollLeft = scrollRatioX * (scrollableContentWidth - viewportWidth);
}

viewportRef.current.scrollLeft = newScrollLeft;
}
Expand Down

0 comments on commit 89e5913

Please sign in to comment.