baianat / hooper

🎠 A customizable accessible carousel slider optimized for Vue
https://baianat.github.io/hooper/
MIT License
720 stars 131 forks source link

Allow slide cancelation in beforeSlide #150

Open cleverplatypus opened 5 years ago

cleverplatypus commented 5 years ago

There are use cases where it would be beneficial for the user to be able to conditionally cancel sliding.

beforeSlide(cancelFn) {
    if(someCondition) {
        cancelFn(); //sliding won't happen
    }
}

Not sure how it would look like in code but there you go. :)

Maybe:

//Carousel.js:192
 methods: {
    // controlling methods
    slideTo(slideIndex, isSource = true) {
      if (this.isSliding || slideIndex === this.currentSlide) {
        return;
      }
      let wasCanceled;

      const cancelFn = () => {
        wasCanceled = true;
      };

      this.$emit('beforeSlide', {
        currentSlide: this.currentSlide,
        slideTo: index
      }, cancelFn);

      if(wasCanceled) {
        return;
      }
//...