From c57fba2c0fa878c31b52dd654413237401a4abd9 Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Mon, 18 Sep 2023 13:38:51 -0400 Subject: [PATCH 1/6] fix(Nav): allow rtl scrolling --- .../react-core/src/components/Nav/NavList.tsx | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/react-core/src/components/Nav/NavList.tsx b/packages/react-core/src/components/Nav/NavList.tsx index acb8de5776e..8c0c65e458a 100644 --- a/packages/react-core/src/components/Nav/NavList.tsx +++ b/packages/react-core/src/components/Nav/NavList.tsx @@ -28,6 +28,7 @@ class NavList extends React.Component { ariaLeftScroll: 'Scroll left', ariaRightScroll: 'Scroll right' }; + private direction = 'ltr'; state = { scrollViewAtStart: false, @@ -51,7 +52,7 @@ class NavList extends React.Component { } }; - scrollLeft = () => { + scrollBack = () => { // find first Element that is fully in view on the left, then scroll to the element before it const container = this.navList.current; if (container) { @@ -65,13 +66,19 @@ class NavList extends React.Component { } } if (lastElementOutOfView) { - container.scrollLeft -= lastElementOutOfView.scrollWidth; + if (this.direction === 'ltr') { + // LTR scrolls left to go back + container.scrollLeft -= lastElementOutOfView.scrollWidth; + } else { + // RTL scrolls right to go back + container.scrollLeft += lastElementOutOfView.scrollWidth; + } } this.handleScrollButtons(); } }; - scrollRight = () => { + scrollForward = () => { // find last Element that is fully in view on the right, then scroll to the element after it const container = this.navList.current; if (container) { @@ -85,7 +92,13 @@ class NavList extends React.Component { } } if (firstElementOutOfView) { - container.scrollLeft += firstElementOutOfView.scrollWidth; + if (this.direction === 'ltr') { + // LTR scrolls right to go forward + container.scrollLeft += firstElementOutOfView.scrollWidth; + } else { + // RTL scrolls left to go forward + container.scrollLeft -= firstElementOutOfView.scrollWidth; + } } this.handleScrollButtons(); } @@ -93,6 +106,7 @@ class NavList extends React.Component { componentDidMount() { this.observer = getResizeObserver(this.navList.current, this.handleScrollButtons, true); + this.direction = getComputedStyle(this.navList.current).getPropertyValue('direction'); this.handleScrollButtons(); } @@ -114,7 +128,7 @@ class NavList extends React.Component {