Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events do not occur when linking images to iOS. #1190

Open
ryoma2na opened this issue Apr 15, 2018 · 8 comments
Open

Events do not occur when linking images to iOS. #1190

ryoma2na opened this issue Apr 15, 2018 · 8 comments

Comments

@ryoma2na
Copy link

ryoma2na commented Apr 15, 2018

When marking up img tag with anchor link, hyperlink event is canceled only on iOS, is this in the specifications?

// Example
<Slider>
  <div><a href=""><img src=""></a></div>
  <div><a href=""><img src=""></a></div>
</Slider>

The following if statement is seemed to be the cause of the problem.

e.target.tagName === "IMG" && e.preventDefault();

In the current situation, not only image links but also onClick events can not be used, so we want at least a click event to be allowed.

@marzelin
Copy link

Have you tried setting pointer-events: none on the images? It might help.

@jeremiah-s-eldridge
Copy link

@marzelin unfortunately if you want to assign a click handler directly to the img then this is still an issue

@LiamKenneth
Copy link

I ran into this issue.

It seems this line:

e.target.tagName === "IMG" && e.preventDefault();

Stops the user from clicking a link that wraps an image. I originally removed the line as pointer-events: none made no difference.

By taking that line out you loose the ability to scroll the slider using the mouse pointer.

So my next solution which seems to have worked is to detect if it's not a mobile device to run this line e.target.tagName === 'IMG' && e.preventDefault()

const isMobileDevice = () => {
  return (typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1);
};

if (!isMobileDevice()) {
    e.target.tagName === 'IMG' && e.preventDefault()
  }

@pmgmendes
Copy link

pmgmendes commented May 21, 2018

Had the same issue. Instead of dealing with react-slick code I replaced my img elements with div elements with a background-image. There's a need to have specific styling in order to make the div emulate the img behavior in terms of sizing.

<div
  className="slick-slider__img"
  style={{
    backgroundImage: "url(" + imageUrl + ")"
  }}
/>

.slick-slider__img {
  width: 95%;
  height: 0;
  padding-top: 95%;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

Thanks everyone by having the time to debug and identify the root cause!

@chrisslater
Copy link

I have encountered this issue with the images but didn't want to drastically change the markup that @pmgmendes recommends.

Instead I created an extra element and added the onclick to that, and then used css to overlay the image

<div className="container">
  <img />
  <div className="hitbox" onClick={...} />
</div>

.container {
  position: relative;
}

.hitbox {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
}

@CodeDeFury
Copy link

CodeDeFury commented Jul 31, 2018

I change the code by removing e.target.tagName === "IMG" && e.preventDefault(); on swipeStart function and change swipeMove to always call e.preventDefault(). This will make sure that the click event will pass through if we are not swiping and desktop image drag default behavior will still be prevented.

Diff of my code change here: CodeDeFury@fdd3f9e

@rostyslavP
Copy link

Any updates in library?

@aorsten
Copy link

aorsten commented Mar 13, 2019

Have you tried setting pointer-events: none on the images? It might help.

I used this to fix the iOS-issue. However, this has the exact opposite effect on Internet Explorer 11, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants