React-slick: Sliding on mobile device scrolls entire page

Created on 21 Jun 2018  路  9Comments  路  Source: akiran/react-slick

I have only seen this happen on an actual mobile device, not in the mobile views available in either Chrome or Safari developer tools.

It appears to only affect iOS (confirmed on iPhone running 11.3 and iPhone 8 Plus running 11.4) and not Android.

React Slick mobile

react-slick-mobile

Slick mobile

slick-mobile

Most helpful comment

You can also solve this by giving the surrounding container a overflow: hidden

All 9 comments

May share a root cause with #1240

This was my solution:

  constructor(props) {
    super(props);

    this.carouselSettings = {..., touchThreshold: 5, ...}; // explicitly set touchThreshold since we reference it later
    this.preventTouch = this.preventTouch.bind(this);
    this.touchStart = this.touchStart.bind(this);
  }

  componentDidMount() {
    // Disable touchmove to prevent scrolling entire page
    const carousel = document.getElementById('someid'); // Your site element containing react-slick's carousel-container
    carousel.addEventListener('touchstart', this.touchStart);
    carousel.addEventListener('touchmove', this.preventTouch, { passive: false });
  }

  touchStart(e) {
    // capture user's starting finger position, for later comparison
    this.firstClientX = e.touches[0].clientX;
  }

  preventTouch(e) {
    // only prevent touch on horizontal scroll (for horizontal carousel)
    // this allows the users to scroll vertically past the carousel when touching the carousel
    // this also stabilizes the horizontal scroll somewhat, decreasing vertical scroll while horizontal scrolling
    const clientX = e.touches[0].clientX - this.firstClientX;
    const horizontalScroll = Math.abs(clientX) > this.carouselSettings.touchThreshold;
    if (horizontalScroll) {
      e.preventDefault();
    }
  }

Thanks to @yunyong for his helpful comment.

You can also solve this by giving the surrounding container a overflow: hidden

That's right, @renetalk , but I'd like to point out that it's the react-slick container.

.slick-slider {
  overflow: hidden;
}

Problem with the overflow: hidden hack is that the dots are then missing and I'm not able to bring them back somehow

Or just disable the arrows thats working better.

.slick-slider {
overflow: hidden;
}

funcional para mim, valeu mesmo!!!

.slick-slider {
overflow: hidden;
}
now dots are gone

.slick-slider {
overflow: hidden;
}
.slick-dots {
position: static;
}

Now It will works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

briziel picture briziel  路  3Comments

darkalor picture darkalor  路  4Comments

vugman picture vugman  路  3Comments

enriquelopez-atlas picture enriquelopez-atlas  路  3Comments

BradyEdgar94 picture BradyEdgar94  路  3Comments