is-touch-device
is-touch-device copied to clipboard
On EDGE browser the function return "true"
Hi, the module return TRUE for EDGE browser, which in its turn creates bug in airbnb/react-dates. This issue exist even in https://www.airbnb.com/ when browsing with Edge. https://www.screencast.com/t/bDGA6Czw
Many windows laptops these days have touch screens. Are you using Edge on a device that has a touch screen?
Also, I'm unable to view your video because it requires Flash. Can you share it in some other way?
Actually I came here because of airbnb/react-dates. I was using the module, and then found out that it is not working correctly in Edge browser on Windows 10. You can go to https://www.airbnb.com/ and just pick a date range, but first try it on Chrome/Mozilla/IE11 then on Edge to compare them. And here is the related issue on react-dates https://github.com/airbnb/react-dates/issues/697. Thanks.
@arshKhachatryan can you confirm that your device doesn't actually have a touch screen?
Yes, 100% , I am using Lenovo T470, if my laptop has had touch screen, I would have the same problem in other browsers.
@arshKhachatryan I'm unable to reproduce this; can you open up your browser console and provide the results for this code:
[
'ontouchstart' in window,
window.DocumentTouch,
document instanceof window.DocumentTouch,
navigator.maxTouchPoints,
navigator.msMaxTouchPoints
]
Thanks!
const chrome = {
'ontouchstart' in window: false,
window.DocumentTouch: undefined,
document instanceof window.DocumentTouch: Uncaught TypeError: Right-hand side of 'instanceof' is not an object,
navigator.maxTouchPoints: 0,
navigator.msMaxTouchPoints: undefined
}
const Edge = {
'ontouchstart' in window: false,
window.DocumentTouch: undefined,
document instanceof window.DocumentTouch: Invalid operand to 'instanceof': Function expected,
navigator.maxTouchPoints: 2,
navigator.msMaxTouchPoints: undefined
}
const EdgeOnPC = {
/* the rest values are the same*/
navigator.maxTouchPoints: 0
}
@ljharb I made a little research, and it turned out, that on pc, navigator.maxTouchPoints returns 0, though in my laptop is returns 2, but on laptop my other browsers return 0 for navigator.maxTouchPoints. I think depending on laptop model, browsers may give different values which I assume is related to the touch-pads that specific laptop, notebook uses. If navigator.maxTouchPoints equals 2 for not all touch devices, only for those that are not not touch devices like my laptop, I think navigator.maxTouchPoints: 2 case can be put in the code as an exception.
That seems premature; given that the spec says that any touchPoints value > 1 indicates touch support. Is there a chance that your laptop's trackpad has multitouch?
(Also, what's the value of window.PointerEvent in those browsers?)
I'm particularly looking at https://patrickhlauke.github.io/touch/touchscreen-detection/ as an alternative.
Yes my laptop's trackpad has multitouch. Is there any specific value you want from this window.PointerEvent?
And unfortunately this https://patrickhlauke.github.io/touch/touchscreen-detection/ also detected touchscreen in my EDGE
If it's got multitouch, it's a touch device - I'm not sure there's an issue here (altho it's surprising that Chrome doesn't report it as one)
The confusion from my part is that only the EDGE treats it as an touch device, others do not,
Right - i'm not clear on whether that's an Edge bug, or a bug in those other browsers.
I had the same problem, and we had to fallback to Modernizr's version:
https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
A bit late to the party but there is a confirmed bug in Edge. Not sure if this was the current Edge version when the issue was initially raised.
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/20417074/
Just updated MS Edge to latest version and the bug is gone. Edge v79+ uses chromium-based engine which works as expected.
I am using this:
const supportsTouch = 'ontouchstart' in window || window.navigator.maxTouchPoints > 0 || window.navigator.msMaxTouchPoints > 0;