React-slick: Sliding broken when slide content is wrapped in anchor tag

Created on 17 Jul 2018  路  7Comments  路  Source: akiran/react-slick

example on CodeSandbox

When slide content is wrapped inside <a /> tag, sliding behaves weirdly; unusable on FF and Safari, Chrome deals with it somehow.

I believe this comes from here:

img elements and a elements with an href attribute have their draggable attribute set to true by default.

HTML spec - Drag and drop

Here's the code I think is related to this, with the proposed solution:

export const swipeStart = (e, swipe, draggable) => {
  e.target.tagName === "IMG" && e.preventDefault();

+  // my proposed solution
+  e.target.tagName === "A" && e.preventDefault();

  if (!swipe || (!draggable && e.type.indexOf("mouse") !== -1)) return "";
  return {
    dragging: true,
    touchObject: {
      startX: e.touches ? e.touches[0].pageX : e.clientX,
      startY: e.touches ? e.touches[0].pageY : e.clientY,
      curX: e.touches ? e.touches[0].pageX : e.clientX,
      curY: e.touches ? e.touches[0].pageY : e.clientY
    }
  };
};

source

What do you think?

All 7 comments

you can solve this problem if you adds the draggable attribute setted by false.

@franciscomorais try it on the codesandbox link I provided - it does not work

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

this is not stale, the problem still occurs

@selrond your fix is definitely needed !!! maybe you should open the PR :) If no I won't resist to do it 馃槃

@Xb0X go ahead!

Is this fixed yet? Seeing this issue in production and not sure how to proceed. Is this only a React-Slick issue or Slick Carousel in general? I swear this type of formatting has worked when called .slick() in the jQuery implementation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ramyatrouny picture ramyatrouny  路  3Comments

vugman picture vugman  路  3Comments

Exomnius picture Exomnius  路  3Comments

rohitgoyal7 picture rohitgoyal7  路  3Comments

will88 picture will88  路  3Comments