react-slick icon indicating copy to clipboard operation
react-slick copied to clipboard

Sliding broken when slide content is wrapped in anchor tag

Open selrond opened this issue 6 years ago • 8 comments

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?

selrond avatar Jul 17 '18 14:07 selrond

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

franciscomorais avatar Sep 21 '18 16:09 franciscomorais

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

selrond avatar Sep 22 '18 08:09 selrond

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.

stale[bot] avatar Sep 17 '19 09:09 stale[bot]

this is not stale, the problem still occurs

selrond avatar Sep 20 '19 10:09 selrond

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

Xb0X avatar Oct 14 '20 08:10 Xb0X

@Xb0X go ahead!

selrond avatar Oct 14 '20 16:10 selrond

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

Mikhail-MM avatar May 29 '21 16:05 Mikhail-MM

@Mikhail-MM @selrond

Here's a fix,

  1. set the draggable attribute to true on the tag
  2. and onDragStart={(e) => e.preventDefault()}
<Slider {...sliderSettings}>
  <div>
    <a href="#" draggable="true" onDragStart={(e) => e.preventDefault()}>
      <BgImage url="http://placekitten.com/g/400/200" />
    </a>
  </div>
// ... other slider items
</Slider>

Here's the working CSB link - https://codesandbox.io/s/react-slick-forked-v79dnj?file=/src/index.js

ashraf-gemini avatar Aug 23 '23 17:08 ashraf-gemini