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

onClick on mobile not fired #2055

Closed
taddei opened this issue Aug 16, 2014 · 20 comments
Closed

onClick on mobile not fired #2055

taddei opened this issue Aug 16, 2014 · 20 comments

Comments

@taddei
Copy link

taddei commented Aug 16, 2014

I have put together a test case that replicates the issue:

https://github.com/taddei/react-bug-test

On desktop browsers the click handler is triggered correctly, the same code on iOS mobile devices (tested both on simulator and actual devices) does not fire the event. Works fine on android.

@waldreiter
Copy link
Contributor

Can you try adding cursor:'pointer' to the css style of the element that you want to click?

@taddei
Copy link
Author

taddei commented Aug 16, 2014

http://www.quirksmode.org/blog/archives/2010/10/click_event_del_1.html

@taddei taddei closed this as completed Aug 16, 2014
@taddei
Copy link
Author

taddei commented Aug 16, 2014

Now, the strange thing is ...
While I was trying to debug this I used a workaround. On componentDidMount I attached a native event listener to the this.getDOMNode() element and removed the listener on componentWillUnmount.
Without the cursor:pointer class on iOS it worked perfectly.

@syranide
Copy link
Contributor

@taddei Yeah, that's "expected", React attaches event listeners to the document. iOS doesn't fire click events for nodes (at all) unless they seem "clickable" (i.e., has a click event listener or cursor: pointer).

@sophiebits
Copy link
Collaborator

See #1169.

@pke
Copy link

pke commented Mar 11, 2016

Adding the cursor: pointer style does not seem to fix this on iOS9 Have to use "react-tappable" to get the clicks recognized instantly

@sophiebits
Copy link
Collaborator

This should have been fixed in 0.14 already.

@pke
Copy link

pke commented Mar 11, 2016

It isn't. I'm on 0.14.7

@joshjhargreaves
Copy link

Any updates on this?

@sophiebits
Copy link
Collaborator

This is closed which indicates no one is looking at it.

But http://react.jsbin.com/mimovoluci uses React 15 and works on my iPhone. Can someone post an example that is broken?

@pke
Copy link

pke commented May 26, 2016

@spicyj by "works on my iPhone" you mean the click is instantly recognized? There is no touch delay?

@sophiebits
Copy link
Collaborator

Oh, I totally misunderstood you. It is expected that you get the same click delay as any other onclick handler. The bug that this was tracking is that clicks didn't work at all on iOS. You have to use something like react-tappable that listens to touch events or a script like fastclick.

@pke
Copy link

pke commented May 26, 2016

@spicyj yeah, I am using react-tappable for that reason. Though react brings something with it by now, to get rid of react-tappable

@brunogarcia
Copy link

@spicyj I've tried the example from jsbin, but doesn't work in Safari 9.0.
By the way on Chrome 51.0.2 works perfectly.
Both tested into an iPad 9.1.

@elonmuscedo
Copy link

I am using React 15, and this works everywhere but iphone 4, ios 8. I tried buttons, a tag but cant that click to run a function.

@AustinSpinazze
Copy link

This appears to be broken again in v16 React. I have tried the cursor pointer fix and it still does not fire correctly. I have to resort to using both onClick and onTouchStart.

@gaearon
Copy link
Collaborator

gaearon commented May 1, 2021

Please file a new issue if you see a new problem. Issues from 2014 aren't actively monitored and the reasons are likely different.

@pke
Copy link

pke commented Sep 15, 2021

but why Dan? This issue shows the history of the problem. Creating a new one just fragments issue for no reason (except that this one here is old).

@thusinh1969
Copy link

It is annoying really ! It is simply stop accepting click for whatever reason ! Is that because Apple want everyone on app ?

Steve

@rickhanlonii
Copy link
Member

Hey all, I'm going to lock this because I'm worried comments for this will be missed, or that people may pattern match this issue with a new issues which is very likely to have a different cause. If you're seeing issues related to onClick not firing, please submit a new issue with a full reproduction in a codesandbox.

@facebook facebook locked as resolved and limited conversation to collaborators Sep 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests