Replace touch and mouse events with pointer events
See original GitHub issueThe library currently uses mouse
and touch
event bindings from V1 when IE11 was supported. All currently targeted browsers support pointer
events so they should be used instead.
See https://github.com/nerdyman/react-compare-slider/commit/5c84c5c7334dd2724d12a4c6e0eba043dd6aa687 (full file here) for a reference implementation.
Requirements
- Add
touchAction: 'none'
style property to root element - Replace
mousedown
event binding withpointerdown
- Remove
touchstart
event binding - Update mouse and touch handlers to replace
MouseEvent | TouchEvent
withPointerEvent
- Remove
instanceof
ternaries in mouse and touch handlers, we can useev.pageX
andev.pageY
Testing
- Test on iOS Safari
- Test on Firefox Android
- Test on Chrome Safari
- Test on Android Chrome
- Test on Desktop Safari
- Test on Desktop Chrome
- Test on Desktop Firefox
Notes
Some automated testing with Storybook has been set up in #65 so it’s probably worth waiting for that to be merge before starting this.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Replacing MouseEvents with PointerEvents
Pointer Events provide all the usual properties present in Mouse Events (client coordinates, target element, button states, etc.) in addition to ...
Read more >Pointer events - The Modern JavaScript Tutorial
Pointer events are a modern way to handle input from a variety of pointing devices, such as a mouse, a pen/stylus, a touchscreen,...
Read more >Pointer events - Web APIs | MDN
Mouse events can only be prevented when the pointer is down. · Hovering pointers (e.g. a mouse with no buttons pressed) cannot have...
Read more >Learn Pointer Events In 15 Minutes - YouTube
Almost everyone defaults to using mouse events such as mousedown and mouseup, but this is not ideal. Mouse events do not include things...
Read more >Pointer Events - W3C
Any touch contact, pen stylus, mouse cursor, or other pointer that can produce events. If it is possible for a given pointer (identified...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nerdyman If this issue requires the work of just replacing the events in the code I could do that. I’ll try to fix this issue with the help of your PR. If I will not able to do it I’ll tell you.
@muditchoudhary Those events need removed/replaced with
pointerup
andpointermove
events. I’ve updated the description for this issue to include links to the full file and also to the previously closed PR. Note that the linked PR also includes a newtransition
feature, that feature is not part of this ticket, just the pointer events changes listed in the description of this issue.Here’s a link to the diff for the pointer events in that PR. The styles for the root element are in
rootStyles
in the main component.The linked PR should have everything needed to check the requirements for this PR. This isn’t the simplest issue so if you’d like something else for Hacktoberfest #75 is also open.