Skip to content

Commit

Permalink
Added physicalKeyboardHighlightPress option. Fixes #735
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgef committed Oct 21, 2020
1 parent 114f825 commit 56fc194
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build/css/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/css/index.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions build/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ declare module 'simple-keyboard' {
*/
physicalKeyboardHighlight?: boolean;

/**
* Presses keys highlighted by physicalKeyboardHighlight
*/
physicalKeyboardHighlightPress?: boolean;

/**
* Define the text color that the physical keyboard highlighted key should have.
*/
physicalKeyboardHighlightTextColor?: string;

/**
* Define the background color that the physical keyboard highlighted key should have.
*/
physicalKeyboardHighlightBgColor?: string;

/**
* Calling preventDefault for the mousedown events keeps the focus on the input.
*/
Expand All @@ -107,16 +122,6 @@ declare module 'simple-keyboard' {
*/
stopMouseUpPropagation?: boolean;

/**
* Define the text color that the physical keyboard highlighted key should have.
*/
physicalKeyboardHighlightTextColor?: string;

/**
* Define the background color that the physical keyboard highlighted key should have.
*/
physicalKeyboardHighlightBgColor?: string;

/**
* Render buttons as a button element instead of a div element.
*/
Expand Down
4 changes: 2 additions & 2 deletions build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-keyboard",
"version": "2.31.12",
"version": "2.32.0",
"description": "On-screen Javascript Virtual Keyboard",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
25 changes: 15 additions & 10 deletions src/lib/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ declare module 'simple-keyboard' {
*/
physicalKeyboardHighlight?: boolean;

/**
* Presses keys highlighted by physicalKeyboardHighlight
*/
physicalKeyboardHighlightPress?: boolean;

/**
* Define the text color that the physical keyboard highlighted key should have.
*/
physicalKeyboardHighlightTextColor?: string;

/**
* Define the background color that the physical keyboard highlighted key should have.
*/
physicalKeyboardHighlightBgColor?: string;

/**
* Calling preventDefault for the mousedown events keeps the focus on the input.
*/
Expand All @@ -107,16 +122,6 @@ declare module 'simple-keyboard' {
*/
stopMouseUpPropagation?: boolean;

/**
* Define the text color that the physical keyboard highlighted key should have.
*/
physicalKeyboardHighlightTextColor?: string;

/**
* Define the background color that the physical keyboard highlighted key should have.
*/
physicalKeyboardHighlightBgColor?: string;

/**
* Render buttons as a button element instead of a div element.
*/
Expand Down
5 changes: 3 additions & 2 deletions src/lib/components/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ class SimpleKeyboard {
* @property {object} maxLength Restrains simple-keyboard’s individual inputs to a certain length. This should be used in addition to the input element’s maxlengthattribute.
* @property {boolean} syncInstanceInputs When set to true, this option synchronizes the internal input of every simple-keyboard instance.
* @property {boolean} physicalKeyboardHighlight Enable highlighting of keys pressed on physical keyboard.
* @property {boolean} physicalKeyboardHighlightPress Presses keys highlighted by physicalKeyboardHighlight
* @property {string} physicalKeyboardHighlightTextColor Define the text color that the physical keyboard highlighted key should have.
* @property {string} physicalKeyboardHighlightBgColor Define the background color that the physical keyboard highlighted key should have.
* @property {boolean} preventMouseDownDefault Calling preventDefault for the mousedown events keeps the focus on the input.
* @property {boolean} preventMouseUpDefault Calling preventDefault for the mouseup events.
* @property {boolean} stopMouseDownPropagation Stops pointer down events on simple-keyboard buttons from bubbling to parent elements.
* @property {boolean} stopMouseUpPropagation Stops pointer up events on simple-keyboard buttons from bubbling to parent elements.
* @property {string} physicalKeyboardHighlightTextColor Define the text color that the physical keyboard highlighted key should have.
* @property {string} physicalKeyboardHighlightBgColor Define the background color that the physical keyboard highlighted key should have.
* @property {function(button: string):string} onKeyPress Executes the callback function on key press. Returns button layout name (i.e.: “{shift}”).
* @property {function(input: string):string} onChange Executes the callback function on input change. Returns the current input’s string.
* @property {function} onRender Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
Expand Down
25 changes: 25 additions & 0 deletions src/lib/services/PhysicalKeyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@ class PhysicalKeyboard {
options.physicalKeyboardHighlightBgColor || "#dadce4";
buttonDOM.style.color =
options.physicalKeyboardHighlightTextColor || "black";

if (options.physicalKeyboardHighlightPress) {
/**
* Trigger mousedown
*/
(
buttonDOM.onpointerdown ||
buttonDOM.onmousedown ||
buttonDOM.ontouchstart ||
Utilities.noop
)();
}
}
});
}

handleHighlightKeyUp(event) {
const options = this.getOptions();
const buttonPressed = this.getSimpleKeyboardLayoutKey(event);

this.dispatch(instance => {
Expand All @@ -48,6 +61,18 @@ class PhysicalKeyboard {

if (buttonDOM && buttonDOM.removeAttribute) {
buttonDOM.removeAttribute("style");

if (options.physicalKeyboardHighlightPress) {
/**
* Trigger mousedown
*/
(
buttonDOM.onpointerup ||
buttonDOM.onmouseup ||
buttonDOM.ontouchend ||
Utilities.noop
)();
}
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/services/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ class Utilities {
word.length ? str + word[0].toUpperCase() + word.slice(1) : str
);
}

static noop = () => {};
}

export default Utilities;
Loading

0 comments on commit 56fc194

Please sign in to comment.