@@ -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' ;
67import * as React from 'react' ;
78
8- import { HiddenText } from '..' ;
9+ import { Text } from '..' ;
910import { FlexBox } from '../Box' ;
1011import {
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