Skip to content

Commit

Permalink
fix(element): don't reinit nested swipers rearranged by parent swiper…
Browse files Browse the repository at this point in the history
… loop

fixes #6642
  • Loading branch information
nolimits4web committed May 8, 2023
1 parent aa83a03 commit 926828a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/loop/loopFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ export default function loopFix({

if (isPrev) {
prependSlidesIndexes.forEach((index) => {
swiper.slides[index].swiperLoopMoveDOM = true;
slidesEl.prepend(swiper.slides[index]);
swiper.slides[index].swiperLoopMoveDOM = false;
});
}
if (isNext) {
appendSlidesIndexes.forEach((index) => {
swiper.slides[index].swiperLoopMoveDOM = true;
slidesEl.append(swiper.slides[index]);
swiper.slides[index].swiperLoopMoveDOM = false;
});
}

Expand Down
15 changes: 15 additions & 0 deletions src/element/swiper-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ class SwiperContainer extends ClassToExtend {
}

connectedCallback() {
if (
this.initialized &&
this.nested &&
this.closest('swiper-slide') &&
this.closest('swiper-slide').swiperLoopMoveDOM
) {
return;
}
if (this.init === false || this.getAttribute('init') === 'false') {
addGlobalStyles(true, this);
return;
Expand All @@ -144,6 +152,13 @@ class SwiperContainer extends ClassToExtend {
}

disconnectedCallback() {
if (
this.nested &&
this.closest('swiper-slide') &&
this.closest('swiper-slide').swiperLoopMoveDOM
) {
return;
}
if (this.swiper && this.swiper.destroy) {
this.swiper.destroy();
}
Expand Down

0 comments on commit 926828a

Please sign in to comment.