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

draggable={ false } prevent slide content iteraction

Open epszaw opened this issue 9 years ago • 7 comments

Hello! When I use carousel with not-image elements and set draggable={ false } , all attempts to interact with content are fails. Example:

onClickButton = (e) => {
  console.log(e);
}

...

<Carousel>
  <div>
    <p>Slide 1</p>
    <button onClick={ this.onClickButton } value='Click me!' /> // Not clickable
  </div>
</Carousel>

epszaw avatar Dec 14 '16 14:12 epszaw

Hi,

I've run into this issue too and it looks like it's because this.clickSafe has a default of 'true' which prevents default on the event (in handleClick). When draggable is set to true, it dynamically sets clickSafe depending on whether the user is swiping so it behaves correctly (prevents default only when the user is in the middle of a drag/swipe):

handleClick: function handleClick(e) {
    if (this.clickSafe === true) {
      e.preventDefault();
      e.stopPropagation();

      if (e.nativeEvent) {
        e.nativeEvent.stopPropagation();
      }
    }
  },

  handleSwipe: function handleSwipe(e) {
    if (typeof this.touchObject.length !== 'undefined' && this.touchObject.length > 44) {
      this.clickSafe = true;
    } else {
      this.clickSafe = false;
    }

I think the solution is to default clickSafe to be false when it's defined. In the meantime a quick fix is to call e.stopPropagation() on all your click events so it doesn't bubble up to the carousel.

melissa-hong avatar Jan 06 '17 17:01 melissa-hong

I believe the real issue is that clickSafe is used to protect against drags / swipes, but when returning the list of drag / touch functions, it doesn't account for the fact that no clicks will be possible without the handleSwipe function having been called. The tricky thing is that clickSafe needs to be true for either swiping or dragging (or both), but not when both are false.

I think a potential solution is to update the default to false, and then modify these two bits of code to switch it to true if either dragging / swiping is allowed:

if (self.props.swiping === false) {
  return null;
} else {
  this.clickSafe = true;
}

...

if (self.props.dragging === false) {
  return null;
} else {
  this.clickSafe = true;
}

ritwik avatar Feb 01 '17 07:02 ritwik

Guys, any update on the fix for this issue?

isadovskiy avatar Nov 30 '17 14:11 isadovskiy

This is still an active issue and was addressed with PR #190, PR #220, and PR #266 but they are no longer merge-able into our current repo (so they are closed but the logic they used to solve the problem might still be applicable).

This issue also relates to issue #381.

mariano-formidable avatar Jul 17 '18 23:07 mariano-formidable

Even anchors tags are not working because of this. any work around for that?

varenya avatar Sep 26 '18 04:09 varenya

Here's a PR: https://github.com/FormidableLabs/nuka-carousel/pull/423

jflayhart avatar Oct 07 '18 21:10 jflayhart

fixed in #423

sarmeyer avatar Oct 08 '18 17:10 sarmeyer