mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-04-22 02:36:28 +08:00
Added disableButtonHold option
This commit is contained in:
parent
5fa612a923
commit
04a3c186f0
5
src/lib/@types/index.d.ts
vendored
5
src/lib/@types/index.d.ts
vendored
@ -123,6 +123,11 @@ declare module 'simple-keyboard' {
|
|||||||
*/
|
*/
|
||||||
useMouseEvents?: boolean;
|
useMouseEvents?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable button hold action.
|
||||||
|
*/
|
||||||
|
disableButtonHold?: 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}").
|
||||||
*/
|
*/
|
||||||
|
@ -65,6 +65,7 @@ class SimpleKeyboard {
|
|||||||
* @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.
|
* @property {boolean} useMouseEvents Opt out of PointerEvents handling, falling back to the prior mouse event logic.
|
||||||
* @property {function} destroy Clears keyboard listeners and DOM elements.
|
* @property {function} destroy Clears keyboard listeners and DOM elements.
|
||||||
|
* @property {boolean} disableButtonHold Disable button hold action.
|
||||||
*/
|
*/
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.options.layoutName = this.options.layoutName || "default";
|
this.options.layoutName = this.options.layoutName || "default";
|
||||||
@ -245,6 +246,7 @@ class SimpleKeyboard {
|
|||||||
/**
|
/**
|
||||||
* @type {object} Time to wait until a key hold is detected
|
* @type {object} Time to wait until a key hold is detected
|
||||||
*/
|
*/
|
||||||
|
if (!this.options.disableButtonHold) {
|
||||||
this.holdTimeout = setTimeout(() => {
|
this.holdTimeout = setTimeout(() => {
|
||||||
if (
|
if (
|
||||||
this.isMouseHold &&
|
this.isMouseHold &&
|
||||||
@ -262,6 +264,7 @@ class SimpleKeyboard {
|
|||||||
clearTimeout(this.holdTimeout);
|
clearTimeout(this.holdTimeout);
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles button mouseup
|
* Handles button mouseup
|
||||||
|
@ -1233,3 +1233,13 @@ it('Keyboard destroy will work', () => {
|
|||||||
|
|
||||||
expect(keyboard.keyboardDOM.innerHTML).toBeFalsy();
|
expect(keyboard.keyboardDOM.innerHTML).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Keyboard disableButtonHold will work', () => {
|
||||||
|
testUtil.setDOM();
|
||||||
|
|
||||||
|
let keyboard = new Keyboard({
|
||||||
|
disableButtonHold: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(keyboard.options.disableButtonHold).toBe(true);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user