Skip to content

Commit 3c6a8ee

Browse files
authored
fix(Pagination): Previous and Next Buttons to respect RTL (#3316)
* use useElementDir for Pagination buttons
1 parent efe7e58 commit 3c6a8ee

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
gamut-styles: minor
3+
gamut: minor
4+
---
5+
6+
Updates the Pagination component to have its Previous/Next buttons' icon reflect the correct dir

packages/gamut/src/Pagination/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import {
22
MiniChevronLeftIcon,
33
MiniChevronRightIcon,
44
} from '@codecademy/gamut-icons';
5-
import { useMemo, useState } from 'react';
5+
import { useElementDir } from '@codecademy/gamut-styles';
6+
import { useMemo, useRef, useState } from 'react';
67
import * as React from 'react';
78

8-
import { HiddenText } from '..';
9+
import { Text } from '..';
910
import { FlexBox } from '../Box';
1011
import {
1112
AnimatedFadeButton,
@@ -72,6 +73,8 @@ export const Pagination: React.FC<PaginationProps> = ({
7273
);
7374
const [liveText, setLiveText] = useState('');
7475
const [shownPageArray, setShownPageArray] = useState([0]);
76+
const rootRef = useRef<HTMLDivElement>(null);
77+
const isRtl = useElementDir(rootRef) === 'rtl';
7578

7679
const showSkipToButtons = !!(
7780
(type === undefined && totalPages >= 10) ||
@@ -145,13 +148,16 @@ export const Pagination: React.FC<PaginationProps> = ({
145148
_: 'initial',
146149
sm: `${showSkipToButtons ? getMinWidth({ chapterSize }) : 'initial'}`,
147150
}}
151+
ref={rootRef}
148152
>
149-
<HiddenText aria-live="polite">{liveText}</HiddenText>
153+
<Text aria-live="polite" screenreader>
154+
{liveText}
155+
</Text>
150156
<AnimatedFadeButton
151157
aria-label={`Navigate back to page ${currentPage - 1}`}
152158
buttonType={variant}
153159
href={navigation}
154-
icon={MiniChevronLeftIcon}
160+
icon={isRtl ? MiniChevronRightIcon : MiniChevronLeftIcon}
155161
showButton={currentPage === 1 ? 'hidden' : 'shown'}
156162
onClick={() => changeHandler(currentPage - 1)}
157163
/>
@@ -230,7 +236,7 @@ export const Pagination: React.FC<PaginationProps> = ({
230236
aria-label={`Navigate forward to page ${currentPage + 1}`}
231237
buttonType={variant}
232238
href={navigation}
233-
icon={MiniChevronRightIcon}
239+
icon={isRtl ? MiniChevronLeftIcon : MiniChevronRightIcon}
234240
showButton={currentPage === totalPages ? 'hidden' : 'shown'}
235241
onClick={() => changeHandler(currentPage + 1)}
236242
/>

0 commit comments

Comments
 (0)