mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-02-22 01:29:39 +08:00
Ensure button handler is triggered on physicalKeyboardHighlightPress. Per https://github.com/hodgef/react-simple-keyboard/issues/1386
This commit is contained in:
parent
cc61947fc0
commit
ed2c5ce81d
@ -136,10 +136,17 @@ export interface KeyboardOptions {
|
|||||||
physicalKeyboardHighlight?: boolean;
|
physicalKeyboardHighlight?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Presses keys highlighted by physicalKeyboardHighlight
|
* Calls handler for a button highlighted by physicalKeyboardHighlight
|
||||||
|
* In other words, this calls keyboard.handleButtonClicked(buttonName) on the highlighted button
|
||||||
*/
|
*/
|
||||||
physicalKeyboardHighlightPress?: boolean;
|
physicalKeyboardHighlightPress?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger click on a button's element when using physicalKeyboardHighlightPress
|
||||||
|
* In other words, this calls button.click() on the highlighted button
|
||||||
|
*/
|
||||||
|
physicalKeyboardHighlightPressUseClick?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the text color that the physical keyboard highlighted key should have.
|
* Define the text color that the physical keyboard highlighted key should have.
|
||||||
*/
|
*/
|
||||||
|
@ -29,9 +29,22 @@ class PhysicalKeyboard {
|
|||||||
const buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
const buttonPressed = this.getSimpleKeyboardLayoutKey(event);
|
||||||
|
|
||||||
this.dispatch((instance: any) => {
|
this.dispatch((instance: any) => {
|
||||||
const buttonDOM =
|
const standardButtonPressed = instance.getButtonElement(buttonPressed);
|
||||||
instance.getButtonElement(buttonPressed) ||
|
const functionButtonPressed = instance.getButtonElement(
|
||||||
instance.getButtonElement(`{${buttonPressed}}`);
|
`{${buttonPressed}}`
|
||||||
|
);
|
||||||
|
let buttonDOM;
|
||||||
|
let buttonName;
|
||||||
|
|
||||||
|
if (standardButtonPressed) {
|
||||||
|
buttonDOM = standardButtonPressed;
|
||||||
|
buttonName = buttonPressed;
|
||||||
|
} else if (functionButtonPressed) {
|
||||||
|
buttonDOM = functionButtonPressed;
|
||||||
|
buttonName = `{${buttonPressed}}`;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (buttonDOM) {
|
if (buttonDOM) {
|
||||||
buttonDOM.style.backgroundColor =
|
buttonDOM.style.backgroundColor =
|
||||||
@ -40,7 +53,11 @@ class PhysicalKeyboard {
|
|||||||
options.physicalKeyboardHighlightTextColor || "black";
|
options.physicalKeyboardHighlightTextColor || "black";
|
||||||
|
|
||||||
if (options.physicalKeyboardHighlightPress) {
|
if (options.physicalKeyboardHighlightPress) {
|
||||||
buttonDOM.click();
|
if (options.physicalKeyboardHighlightPressUseClick) {
|
||||||
|
buttonDOM.click();
|
||||||
|
} else {
|
||||||
|
instance.handleButtonClicked(buttonName, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user