swiper icon indicating copy to clipboard operation
swiper copied to clipboard

Swiper init incorrectly determining RTL when inside ion-content

Open Farbdose opened this issue 1 year ago • 4 comments

Check that this is really a bug

  • [X] I confirm

Reproduction link

https://stackblitz.com/edit/angular-ywh4p1-vza2cj?file=src%2Fapp%2Fapp.component.html

Bug description

When placing a swiperjs.com swiper inside an ion-content (and rendering it with a delay) the swiper doesn't recognize the surrounding dir="rtl". Only happens with ion-content.

I'm not sure if this is a swiperjs problem or an ionic problem but ionic asked me to create an issue here too: https://github.com/ionic-team/ionic-framework/issues/29368#issuecomment-2069581280

Expected Behavior

rtl should propagate through ion-content regardless of when the component is rendered.

Actual Behavior

  1. create a div with dir="rtl"
  2. put a swiper inside an ion-content inside the div and render it a few ticks later using ngIf
  3. try swiping
  4. swiper doesn't swipe

See linked stackblitz, first swiper works on clean page load but breaks after stackblitz livereload, second swiper doesn't work at all, 3rd and 4th work.

Swiper version

11

Platform/Target and Browser Versions

macOS Chrom 124

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the docs.
  • [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • [X] Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • [ ] I'm willing to open a PR

Farbdose avatar Apr 23 '24 06:04 Farbdose

Based on what I've seen so far it looks like the swiper init runs before the swiper element itself is fully integrated in the dom making it not recognize the surrounding style rules as it's still floating somewhere in the deep dark shadow dom.

Get Computed Style reports ltr while theoretically inside the div with RTL and only switches to RTL a few ticks later.

I observed this a few days ago and couldn't find the actual init code, which lead to me creating a feature request https://github.com/nolimits4web/swiper/issues/7479 which got promptly shut down without asking why I may have asked for something that should be already present - my enthusiasmus to create a pr for this has somewhat diminished since then.

Farbdose avatar Apr 23 '24 07:04 Farbdose

Wanted to cross post my findings regarding this issue: https://github.com/ionic-team/ionic-framework/issues/29368#issuecomment-2075776241

This was originally reported as an Ionic Framework issue, but the root cause appears to be related to how inheritance works with slotted content.

liamdebeasi avatar Apr 24 '24 20:04 liamdebeasi

t0ggles-create swiper

nolimits4web avatar Apr 24 '24 21:04 nolimits4web

Task nolimits4web/SWIPER-94 was created

t0ggles task SWIPER-94

t0ggles[bot] avatar Apr 24 '24 21:04 t0ggles[bot]

I am not sure what else we can do here on Swiper side. It is already initialized only within a connected callback. And here is the example of when it is placed inside of the multiple custom elements components https://codepen.io/nolimits4web/pen/eYwvObb. Everything works as expected

nolimits4web avatar Jul 31 '24 11:07 nolimits4web

The issue was unlinked from the task nolimits4web/SWIPER-94

t0ggles[bot] avatar Jul 31 '24 11:07 t0ggles[bot]