From 30941f4ba0d3afd768b0ddc10cabd12bc6efefbd Mon Sep 17 00:00:00 2001 From: Francisco Hodge Date: Thu, 7 Mar 2019 20:51:29 -0500 Subject: [PATCH] Adding useMouseEvents option --- src/lib/@types/index.d.ts | 5 +++++ src/lib/components/Keyboard.js | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/@types/index.d.ts b/src/lib/@types/index.d.ts index de878cf6..d6e9322d 100644 --- a/src/lib/@types/index.d.ts +++ b/src/lib/@types/index.d.ts @@ -121,6 +121,11 @@ declare module 'simple-keyboard' { */ autoUseTouchEvents?: boolean; + /** + * Opt out of PointerEvents handling, falling back to the prior mouse event logic. + */ + useMouseEvents?: boolean; + /** * Executes the callback function on key press. Returns button layout name (i.e.: "{shift}"). */ diff --git a/src/lib/components/Keyboard.js b/src/lib/components/Keyboard.js index 32705a78..1ba0ab69 100644 --- a/src/lib/components/Keyboard.js +++ b/src/lib/components/Keyboard.js @@ -63,6 +63,7 @@ class SimpleKeyboard { * @property {object} inputPattern Restrains input(s) change to the defined regular expression pattern. * @property {boolean} useTouchEvents Instructs simple-keyboard to use touch events instead of click events. * @property {boolean} autoUseTouchEvents Enable useTouchEvents automatically when touch device is detected. + * @property {boolean} useMouseEvents Opt out of PointerEvents handling, falling back to the prior mouse event logic. */ this.options = options; this.options.layoutName = this.options.layoutName || "default"; @@ -843,6 +844,7 @@ class SimpleKeyboard { let layout = this.options.layout || KeyboardLayout.getDefaultLayout(); let useTouchEvents = this.options.useTouchEvents || false; let useTouchEventsClass = useTouchEvents ? "hg-touch-events" : ""; + let useMouseEvents = this.options.useMouseEvents || false; /** * Account for buttonTheme, if set @@ -895,7 +897,11 @@ class SimpleKeyboard { * Handle button click event */ /* istanbul ignore next */ - if (this.utilities.pointerEventsSupported() && !useTouchEvents) { + if ( + this.utilities.pointerEventsSupported() && + !useTouchEvents && + !useMouseEvents + ) { /** * PointerEvents support */