Skip to content

Commit

Permalink
fix(event): Update determination condition
Browse files Browse the repository at this point in the history
Add browser sniffing to determine 'mobile' touch to be distinguished
with the desktop with the touch support.

Ref #967
  • Loading branch information
netil committed Jul 16, 2019
1 parent 8b4e3eb commit 736ba56
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/internals/ChartInternal.js
Original file line number Diff line number Diff line change
Expand Up @@ -1288,20 +1288,23 @@ export default class ChartInternal {
convertInputType() {
const $$ = this;
const config = $$.config;
const isMobile = (
window.navigator && "maxTouchPoints" in window.navigator && window.navigator.maxTouchPoints > 0
) || false;
let isMobile = false;

const hasMouse = config.interaction_inputType_mouse && !isMobile ? ("onmouseover" in window) : false;
let hasTouch = false;
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#Mobile_Tablet_or_Desktop
if (/Mobi/.test(window.navigator.userAgent) && config.interaction_inputType_touch) {
// Some Edge desktop return true: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/20417074/
const hasTouchPoints = window.navigator && "maxTouchPoints" in window.navigator && window.navigator.maxTouchPoints > 0;

if (config.interaction_inputType_touch) {
// Ref: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
// On IE11 with IE9 emulation mode, ('ontouchstart' in window) is returning true
hasTouch = ("ontouchmove" in window) || (window.DocumentTouch && document instanceof window.DocumentTouch);
const hasTouch = ("ontouchmove" in window || (window.DocumentTouch && document instanceof window.DocumentTouch));

isMobile = hasTouchPoints || hasTouch;
}

return (hasMouse && "mouse") || (hasTouch && "touch") || null;
const hasMouse = config.interaction_inputType_mouse && !isMobile ? ("onmouseover" in window) : false;

return (hasMouse && "mouse") || (isMobile && "touch") || null;
}

/**
Expand Down

0 comments on commit 736ba56

Please sign in to comment.