onTouchEnd leads to focus on inputs that are rendered after the touch
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
An onTouchEnd event that leads to the rendering of an input element at the location of the original touched element will focus the input element, which means that the touch is reused for the new input element.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/reactjs/69z2wepo/).
You can check out the following fiddle to reproduce it: https://jsfiddle.net/7bxvby79/2/
- Open the mobile device mode in chrome, or open the fiddle from a touch device
- Zoom in so that a touch on "Click here" will fully land (theoretically) in the input element behind it (Double click somewhere)
- Touch "Click here" -> The input element is now focused.
You can also see this gif in case the repro steps are unclear: http://giphy.com/gifs/3o7TKFm2J9LAs1zn6U
What is the expected behavior?
The input element should not be focused, because it does not exist when it is touched yet.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
15.4.1, it does also not work on 15.3., Chrome, Android Chrome Web View, maybe more browsers
Btw if the event is changed to onClick or onMouseUp the input will not receive the focus after a click/touch.
The workaround for our project is:
Always call event.preventDefault() in our interaction component (=Button) if it has a callback to execute on onTouchEnd because it could possibly lead to a new site (via react-router) which contains input components.
I feel definitely not comfortable doing this - are there any other quick solutions?
After a little investigation in Chrome I noticed React is receiving both onTouchEnd and onClick events. The onTouchEnd event triggers the updates to the tree, which means by the time the onClick fires, its target ends up being the input. It looks like the w3c spec says firing both events is okay/expected behavior.
The user agent may dispatch both touch events and mouse events [DOM-LEVEL-2-EVENTS] in response to the same user input.
The existing workaround does seem to be using preventDefault like mentioned.
Seems like we don't need to do anything on our side. Let me know if I misunderstood.