Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic RTL change #3279

Closed
2 of 3 tasks
codesignist opened this issue Oct 15, 2019 · 5 comments
Closed
2 of 3 tasks

Dynamic RTL change #3279

codesignist opened this issue Oct 15, 2019 · 5 comments

Comments

@codesignist
Copy link
Contributor

What you did

I've changed html direction to "rtl" by JS.

document.documentElement.dir = "rtl";

Expected Behavior

RTL change should affect Swiper and should work from right to left as expected.

Actual Behavior

RTL change doesn't make any effect on Swiper.

@nolimits4web
Copy link
Owner

It is by design, it can be initialized when it is rtl or not, and it’s behavior can’t be changed after init. If you really need such behavior you can destroy and reinit Swiper in this case

@EliezerB123
Copy link

EliezerB123 commented Jan 16, 2020

@nolimits4web Why?

It seems that it is already working just fine as is. Why not include it in the official documention?

window.on('myLanguageEvent',function(event){
        swiper.rtl =  (event.direction === 'rtl');
        swiper.rtlTranslate = (event.direction === 'rtl');
});

seems to correctly causes the slider to switch directions properly.

@farhadf246
Copy link

is it possible add direction changes in to the observe parameter? or when call update method update slider direction too?

@Mostafatalaat770
Copy link

@nolimits4web Why?

It seems that it is already working just fine as is. Why not include it in the official documention?

window.on('myLanguageEvent',function(event){
        swiper.rtl =  (event.direction === 'rtl');
        swiper.rtlTranslate = (event.direction === 'rtl');
});

seems to correctly causes the slider to switch directions properly.

This is working great without the rtl property. ReactJs example:

import  React, { useEffect, useState } from 'react'
import { Swiper, SwiperSlide } from 'swiper/react'
import { Swiper as SwiperInstance } from 'swiper'
import i18n from 'i18next'

const Slider = () => {

  const [swiper, setSwiper] = useState<SwiperInstance | null>(null)
  useEffect(() => {
    if (swiper) {
      swiper.rtlTranslate = i18n?.dir() === 'rtl'
    }
  }, [swiper, i18n?.dir()])

  return (
    <Swiper
      spaceBetween={50}
      slidesPerView={3}
      onSwiper={(swiper : SwiperInstance) => setSwiper(swiper)}
    >
      <SwiperSlide>Slide 1</SwiperSlide>
      <SwiperSlide>Slide 2</SwiperSlide>
      <SwiperSlide>Slide 3</SwiperSlide>
      <SwiperSlide>Slide 4</SwiperSlide>
      ...
    </Swiper>
  )
}

@kirillsakun
Copy link

kirillsakun commented Jan 17, 2023

Seems like it doesn't reset margins that were added by spaceBetween option and breaks if slidesPerView option is set to 'auto'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants