nearform / react-browser-hooks

React Browser Hooks
https://react-browser-hooks.netlify.com
Other
127 stars 10 forks source link

Mouse Events #22

Open cianfoley-nearform opened 5 years ago

cianfoley-nearform commented 5 years ago

Investigate and integrate Mouse Events and some handy features e.g.

position already done, but should be part of mouse suite that can work together:

e.g. click outside double clicks vs single (timer based maybe configurable) right click pass in element or default to page (resize will need rework for this) hover, again could be page vs element

all of these could be individual hooks, possibly could be justified to be in it's own lib

jh3y commented 5 years ago

Worth thinking about how useful some of these would be or prioritising what would be useful. Many of the scenarios could be covered by the current set of synthetic events on offer. Creating a pass through function would over complicate things: https://reactjs.org/docs/events.html#supported-events

cianfoley-nearform commented 5 years ago

Sure, i think there's issue between determining single vs double click, again browserwide, the click outside should be a common enough use case too

jh3y commented 5 years ago

There is an onDoubleClick in the docs.

Yeah. The off click could be a great one to implement. It's a tricky one I've written about before 👍

cianfoley-nearform commented 5 years ago

Yeah I know about doubleclick but AFAIK the single click is also set off by doubleclick (could be wrong here), we had a situation before where if doubleclick is clicked we don't want single click being triggered, it might be a usecase e.g. if doubleclick doesn't happen within X, raise singleclick events sort of thing and maybe apply to offclick if that was nailed too...

jh3y commented 5 years ago

Nope that's completely correct 👍

The way I've tackled this previously is to store setInterval invocations in an Array in state and if doubleClick is fired, clear the intervals.

There's a rough example in this code: https://codepen.io/jh3y/pen/aPzVme

Could be a good gotcha one to implement a hook for 👍