vue-carousel icon indicating copy to clipboard operation
vue-carousel copied to clipboard

Bug: `VueCarousel-slide-active` is not added as a class to the first slide on initial load

Open ckhatton opened this issue 4 years ago • 4 comments

Bug Report

I have found that VueCarousel-slide-active is not added as a class to the first slide on initial load. So I had to add this below to my component script after applying a dynamic "id" to each slide (I couldn't use $refs as the slides are printed out using a v-for loop).

export default {
//...
  mounted: function() {
    document.getElementById('VueCarousel-slide-0').classList.add('VueCarousel-slide-active');
  }
//...
}

Without this it means that one cannot target the active slide with personalised styling until the slide is interacted with.

Environment

  • Node/npm version: Node v11.1.0/npm 6.14.3
  • OS: OSX 10.14.6

Referenced originally in Issue #223.

:octocat:

ckhatton avatar Mar 21 '20 01:03 ckhatton

didn't work for me :/

gbrlcardozo avatar Apr 22 '20 15:04 gbrlcardozo

My work around @gbrlcardozo?

You have to make sure you add the corresponding ID 'VueCarousel-slide-0' to the first slide component. If the slide component is part of a v-for loop, then you can add something like :id="'VueCarousel-slide-' + index".

ckhatton avatar Apr 22 '20 15:04 ckhatton

Slightly tidier version for anyone running into this, noticing it doesn't prevent the translate when dragging on mobile though.

Step 1: Add ref="slide" to <slide>

Step 2: Add following to component

mounted() {
  this.$nextTick(() => {
    this.$refs.slide[0].$el.classList.add('VueCarousel-slide-active');
  });
},

joeswann avatar Sep 28 '20 00:09 joeswann

Even after doing this, navigating the first time doesn't remove the slide-active class from the first slide. This is unexpected functionality.

jasonbodily avatar Apr 05 '22 17:04 jasonbodily