1
1
import { PaginationItemValue } from "@nextui-org/use-pagination" ;
2
2
import { useCallback } from "react" ;
3
+ import { useLocale } from "@react-aria/i18n" ;
3
4
import { forwardRef } from "@nextui-org/system" ;
4
5
import { PaginationItemType } from "@nextui-org/use-pagination" ;
5
6
import { ChevronIcon , EllipsisIcon , ForwardIcon } from "@nextui-org/shared-icons" ;
@@ -35,6 +36,10 @@ const Pagination = forwardRef<"nav", PaginationProps>((props, ref) => {
35
36
getCursorProps,
36
37
} = usePagination ( { ...props , ref} ) ;
37
38
39
+ const { direction} = useLocale ( ) ;
40
+
41
+ const isRTL = direction === "rtl" ;
42
+
38
43
const renderItem = useCallback (
39
44
( value : PaginationItemValue , index : number ) => {
40
45
const isBefore = index < range . indexOf ( activePage ) ;
@@ -114,7 +119,7 @@ const Pagination = forwardRef<"nav", PaginationProps>((props, ref) => {
114
119
} ) }
115
120
data-slot = "prev"
116
121
getAriaLabel = { getItemAriaLabel }
117
- isDisabled = { ! loop && activePage === 1 }
122
+ isDisabled = { ! loop && activePage === ( isRTL ? total : 1 ) }
118
123
value = { value }
119
124
onPress = { onPrevious }
120
125
>
@@ -131,7 +136,7 @@ const Pagination = forwardRef<"nav", PaginationProps>((props, ref) => {
131
136
} ) }
132
137
data-slot = "next"
133
138
getAriaLabel = { getItemAriaLabel }
134
- isDisabled = { ! loop && activePage === total }
139
+ isDisabled = { ! loop && activePage === ( isRTL ? 1 : total ) }
135
140
value = { value }
136
141
onPress = { onNext }
137
142
>
@@ -163,7 +168,7 @@ const Pagination = forwardRef<"nav", PaginationProps>((props, ref) => {
163
168
< EllipsisIcon className = { slots ?. ellipsis ( { class : classNames ?. ellipsis } ) } />
164
169
< ForwardIcon
165
170
className = { slots ?. forwardIcon ( { class : classNames ?. forwardIcon } ) }
166
- data-before = { dataAttr ( isBefore ) }
171
+ data-before = { dataAttr ( isRTL ? ! isBefore : isBefore ) }
167
172
/>
168
173
</ PaginationItem >
169
174
) ;
@@ -175,7 +180,18 @@ const Pagination = forwardRef<"nav", PaginationProps>((props, ref) => {
175
180
</ PaginationItem >
176
181
) ;
177
182
} ,
178
- [ activePage , dotsJump , getItemProps , loop , range , renderItemProp , slots , classNames , total ] ,
183
+ [
184
+ isRTL ,
185
+ activePage ,
186
+ dotsJump ,
187
+ getItemProps ,
188
+ loop ,
189
+ range ,
190
+ renderItemProp ,
191
+ slots ,
192
+ classNames ,
193
+ total ,
194
+ ] ,
179
195
) ;
180
196
181
197
return (
0 commit comments