JakeSidSmith / react-fastclick

Fast Touch Events for React
https://www.npmjs.com/package/react-fastclick
MIT License
487 stars 41 forks source link

select and input in the handleType method did not prevent the default event #48

Closed duanlixin closed 7 years ago

duanlixin commented 7 years ago

A page, if there are more than one select element, when clicking on one of the select, will cause the other select elements are clicked

https://github.com/JakeSidSmith/react-fastclick/blob/master/src/index.js#L47

Solution:

Input and select Add to prevent default events

Code:

var handleType = {

input: function (event) {
  focus(event);
  **event. preventDefault();**
  event.stopPropagation();
},
textarea: function (event) {
  focus(event);
  event.stopPropagation();
},
select: function (event) {
  focus(event);
  **event. preventDefault();**
  event.stopPropagation();
},
JakeSidSmith commented 7 years ago

Other inputs & selects on the page are clicked?

Do you mean that their onClick callbacks are triggered?

This should not be possible due to the check for the bounding box here: https://github.com/JakeSidSmith/react-fastclick/blob/master/src/index.js#L169

JakeSidSmith commented 7 years ago

Is the issue on a touch device, or when using a mouse / trackpad? @duanlixin

duanlixin commented 7 years ago

yes, on a touch device, Browser simulation is good。

JakeSidSmith commented 7 years ago

And it is their onClick handler that is being triggered? Are you using any libraries that may affect this?

duanlixin commented 7 years ago

yes, their onClick handler triggered. i'm nont using any other libraries. do you need a example ?

JakeSidSmith commented 7 years ago

A screenshot and a snippet of JSX would be good. :)

bradennapier commented 7 years ago

+1 - if you dont do this you cant use input elements at all on mobile -- in my case every time i selected an input it would unselect it immediately.

JakeSidSmith commented 7 years ago

Please try the alpha version I've just released and let me know if it's fixed this issue for you. :)

https://github.com/JakeSidSmith/react-fastclick/pull/50