Skip to content

Commit f4a4d66

Browse files
xiaoyatongxiaoyatong
andauthored
fix(swiper): rtl (jdf2e#2061)
Co-authored-by: xiaoyatong <hanyuxingint@sina.cn>
1 parent 0c40c77 commit f4a4d66

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/packages/swiper/swiper.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Indicator from '@/packages/indicator/index'
1313
import { BasicComponent } from '@/utils/typings'
1414
import { useTouch } from '@/utils/use-touch'
1515
import requestAniFrame from '@/utils/raf'
16+
import { useRtl } from '@/packages/configprovider'
1617

1718
export type SwiperRef = {
1819
to: (index: number) => void
@@ -59,6 +60,7 @@ export const Swiper = React.forwardRef<
5960
SwiperRef,
6061
Partial<SwiperProps> & Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'>
6162
>((props, ref) => {
63+
const rtl = useRtl()
6264
const mergedProps = { ...defaultProps, ...props }
6365
const {
6466
children,
@@ -304,7 +306,7 @@ export const Swiper = React.forwardRef<
304306
isVertical ? width : height
305307
}px`
306308
target.style.transform = `translate3D${
307-
!isVertical ? `(${_offset}px,0,0)` : `(0,${_offset}px,0)`
309+
!isVertical ? `(${rtl ? -_offset : _offset}px,0,0)` : `(0,${_offset}px,0)`
308310
}`
309311
}
310312

@@ -369,7 +371,9 @@ export const Swiper = React.forwardRef<
369371
const offset = childOffset[index]
370372
if (offset) {
371373
style.transform = `translate3D${
372-
direction === 'horizontal' ? `(${offset}px,0,0)` : `(0,${offset}px,0)`
374+
direction === 'horizontal'
375+
? `(${rtl ? -offset : offset}px,0,0)`
376+
: `(0,${offset}px,0)`
373377
}`
374378
}
375379
return style

0 commit comments

Comments
 (0)