ember-cli-swiper icon indicating copy to clipboard operation
ember-cli-swiper copied to clipboard

Duplicate ids with loop option

Open sebastianhelbig opened this issue 5 years ago • 6 comments

When using the swiper option loop: true, the swiper will duplicate the slides. This leads to having element with duplicate ids in the DOM

<div id="ember343" class="swiper-container ember-view swiper-container-initialized swiper-container-horizontal"><div class="swiper-wrapper" style="transition-duration: 0ms; transform: translate3d(-2583px, 0px, 0px);">
  <div id="ember349" class="swiper-slide ember-view swiper-slide-duplicate" data-swiper-slide-index="1" style="width: 339px; margin-right: 30px;">…</div>
  <div id="ember351" class="swiper-slide ember-view swiper-slide-duplicate" data-swiper-slide-index="2" style="width: 339px; margin-right: 30px;">…</div>
  <div id="ember353" class="swiper-slide ember-view swiper-slide-duplicate swiper-slide-duplicate-prev" data-swiper-slide-index="3" style="width: 339px; margin-right: 30px;">…</div>
  <div id="ember347" class="swiper-slide ember-view swiper-slide-duplicate-active" data-swiper-slide-index="0" style="width: 339px; margin-right: 30px;">…</div>
  <div id="ember349" class="swiper-slide ember-view swiper-slide-duplicate-next" data-swiper-slide-index="1" style="width: 339px; margin-right: 30px;">…</div>
  <div id="ember351" class="swiper-slide ember-view" data-swiper-slide-index="2" style="width: 339px; margin-right: 30px;">…</div>
  …
</div>

sebastianhelbig avatar Jun 30 '19 02:06 sebastianhelbig

I have the same problem. All elements are duplicated, but actions on elements are not. Because of that, some buttons work in the initial slide, but not in the duplicated slide.

driesdl avatar Jan 03 '20 08:01 driesdl

We can look into the duplicate ID issue, however for the actions is there anything preventing you from using event delegation?

Matt-Jensen avatar Jan 03 '20 15:01 Matt-Jensen

I solved the duplicate id issue by extending swiper-slidecomponent and setting tagName: ''.

sebastianhelbig avatar Jan 04 '20 01:01 sebastianhelbig

@sebastianhelbig glad you got it working for you, however this fix doesn't make much sense to me at the moment. Doesn't that remove the slide element (one with the swiper-slide class) from the DOM?

Matt-Jensen avatar Jan 04 '20 18:01 Matt-Jensen

@Matt-Jensen

app/components/swiper-slider.js

import SwiperSlide from 'ember-cli-swiper/components/swiper-slide';

export default SwiperSlide.extend({
  tagName: ''
});

app/templates/components/swiper-slide.hbs

<div class="swiper-slide">
  {{yield}}
</div>

sebastianhelbig avatar Jan 04 '20 22:01 sebastianhelbig

Thanks @sebastianhelbig.

EstesE avatar Feb 25 '20 15:02 EstesE