Adding useMouseEvents option

This commit is contained in:
Francisco Hodge 2019-03-07 20:51:29 -05:00
parent 48a15e6715
commit 30941f4ba0
2 changed files with 12 additions and 1 deletions

View File

@ -121,6 +121,11 @@ declare module 'simple-keyboard' {
*/ */
autoUseTouchEvents?: boolean; 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}"). * Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
*/ */

View File

@ -63,6 +63,7 @@ class SimpleKeyboard {
* @property {object} inputPattern Restrains input(s) change to the defined regular expression pattern. * @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} 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} 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 = options;
this.options.layoutName = this.options.layoutName || "default"; this.options.layoutName = this.options.layoutName || "default";
@ -843,6 +844,7 @@ class SimpleKeyboard {
let layout = this.options.layout || KeyboardLayout.getDefaultLayout(); let layout = this.options.layout || KeyboardLayout.getDefaultLayout();
let useTouchEvents = this.options.useTouchEvents || false; let useTouchEvents = this.options.useTouchEvents || false;
let useTouchEventsClass = useTouchEvents ? "hg-touch-events" : ""; let useTouchEventsClass = useTouchEvents ? "hg-touch-events" : "";
let useMouseEvents = this.options.useMouseEvents || false;
/** /**
* Account for buttonTheme, if set * Account for buttonTheme, if set
@ -895,7 +897,11 @@ class SimpleKeyboard {
* Handle button click event * Handle button click event
*/ */
/* istanbul ignore next */ /* istanbul ignore next */
if (this.utilities.pointerEventsSupported() && !useTouchEvents) { if (
this.utilities.pointerEventsSupported() &&
!useTouchEvents &&
!useMouseEvents
) {
/** /**
* PointerEvents support * PointerEvents support
*/ */