react icon indicating copy to clipboard operation
react copied to clipboard

Support Pointer events specification

Open plievone opened this issue 13 years ago • 40 comments

What is your approach to IE10 touch events?

Hammer.js checks window.navigator.pointerEnabled || window.navigator.msPointerEnabled and then switches touchstart, touchmove, touchend touchcancel to pointerdown MSPointerDown, pointermove MSPointerMove, pointerup pointercancel MSPointerUp MSPointerCancel.

plievone avatar Nov 09 '13 11:11 plievone

@iamdustan Very interesting, but it seems very weird if there will be nothing to replace it.

syranide avatar Aug 12 '14 19:08 syranide

@syranide Agreed. It seems to me like browser engineers are experimenting just like front end engineers are. Not sure if you read the entirety of that document, but it seemed to make mention that there is the possibility of the good parts of pointer events someday migrating into touch events.

iamdustan avatar Aug 12 '14 19:08 iamdustan

@iamdustan Just finished reading it through, very interesting stuff. My takeaway though is that most of the discussion isn't primarily about any short-comings of PointerEvents, but whether or not browsers really should provide such "sugar".

So even if they do end up abandoning it, it may still make sense to provide a way to have it in React (because the demand is real), which naturally leads to the idea of plugging in any event sugar. But it could never benefit third-party components and I feel that many (including me) would be afraid to commit to "any one" community event sugar, they tend to be abandoned on a daily basis.

An interesting alternative (perhaps) after reading through that discussion, what if one could specify event emulation modes per DOM-node, i.e, <div onMouseDown={...} touchEventsAs="mouse" /> and it would emulate mouse-events from touch-events. There are probably flaws I haven't thought of, but it's possible that everyone could benefit and it (hopefully) wouldn't be a big strain on React.

But we'll see where it goes.

syranide avatar Aug 12 '14 19:08 syranide

@syranide how would you imagine the react emulation mode rectify itself with the browser emulated events? (E.g. the iOS touch event cascade: http://www.quirksmode.org/blog/archives/2014/02/the_ios_event_c.html)

iamdustan avatar Oct 07 '14 03:10 iamdustan

@iamdustan I really have no idea, I have thankfully been able to stay away from touch events so far. But I imagine event.preventDefault() in touchend would prevent the cascade, but there are definitely big questionmarks as can be seen in some other issues.

syranide avatar Oct 07 '14 09:10 syranide

If I understand this correctly, we can only simulate a pointerDown event when we have first-class pointer event support in React, correct? I've looked at the source code of https://github.com/zilverline/react-tap-event-plugin/ (and this issue https://github.com/zilverline/react-tap-event-plugin/issues/10) and am very impressed with the sophistication of the React event system. No news on pointerEvent support as of yet, though?

jfahrenkrug avatar Sep 16 '15 18:09 jfahrenkrug

Any update on this? I am adding/removing pointer event listeners for in the component lifecycle.

aaronshaf avatar Dec 11 '16 22:12 aaronshaf

Same question here, I'd love to see it implemented soon.

martpie avatar Dec 12 '16 13:12 martpie

Really needed since pointer events are in Chrome now and going to be shipped in FF

klimashkin avatar Dec 12 '16 19:12 klimashkin

I wrote a component that allows declarative pointer event binding, and has been working for me as an easy substitute until React officially supports them.

Update: <Pointable /> now lives in its own repo and is on npm: https://www.npmjs.com/package/react-pointable

While it's great Chrome and FF are shipping pointer events, Safari is my biggest worry. To that end, this component plays well with the official pointer events polyfill project for wide support.

MilllerTime avatar Dec 13 '16 17:12 MilllerTime

I would love to see this... the parody between onPointerEnter and onMouseEnter is sooooo useful for user experiance

chaffeqa avatar Jan 14 '17 12:01 chaffeqa

@spicyj Is this issue still something we'd want to implement?

anthonybarsotti avatar Mar 16 '17 01:03 anthonybarsotti

If we don't provide a polyfill and just add support for it in the SimpleEventPlugin, the implementation should be relatively straight-forward, right?

This will still allow people to use the popular polyfill if they need pointer events on different platforms. React would simply handle this as another type of native events (similar to SyntheticMouseEvent and SyntheticTouchEvent). If this is something you want to implement I'd love to give it a shot 👍

philipp-spiess avatar Apr 28 '17 10:04 philipp-spiess

@philipp-spiess Even if pointer event support is added to React, integrating with PEP will still require manually setting/removing the touch-action attribute since it's a non-standard workaround required by PEP. Supporting Safari/iOS seems fairly important and touch-action would still be a pain point.

That being said, if pointer events are added to React, I'll update Pointable so it handles touch-action and allows React to do the rest.

MilllerTime avatar Apr 28 '17 17:04 MilllerTime

@MilllerTime Thank you for your input! I agree that the touch-action API is inconvenient. My idea was to simply make React understand pointer events and pool them like touch or mouse events.

Since support for Safari and iOS is vital, we could write a small guide somewhere as well where we explain how a user can set this up with the polyfill. Either by using your package or adding the touch-action property manually.

If a more out-of-the-box support for this polyfill is desired, we could also whitelist the touch-action property on HTML elements here.

philipp-spiess avatar Apr 28 '17 17:04 philipp-spiess

so React still doesn't support

<div onPointerDown={console.log}>foo</div>

the authors don't want it or they are open to a PR?

caub avatar Dec 02 '17 22:12 caub

Firefox 59 just shipped with support for pointer events enabled. There's now mainstream support for every browser except Safari.

elijahdorman avatar Mar 13 '18 15:03 elijahdorman

sounds about right 🙄

chaffeqa avatar Mar 13 '18 15:03 chaffeqa

If anyone would like to add support it's pretty straightforward to add native events. Take a look at SimpleEventPlugin and how the other native events are supported.

There is a question about whether React should polyfill the behave for old browsers, but I think it'll be safe to start with just allowing the native events if anyone wants to give it a shot

jquense avatar Mar 13 '18 16:03 jquense