mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-01-20 01:22:59 +08:00
Handle multiple buttons when using physicalKeyboardHighlight. Fixes https://github.com/hodgef/react-simple-keyboard/issues/2211
This commit is contained in:
parent
08d212d76e
commit
3ad8a9f7fe
@ -34,7 +34,7 @@ class PhysicalKeyboard {
|
||||
`{${buttonPressed}}`
|
||||
);
|
||||
let buttonDOM;
|
||||
let buttonName;
|
||||
let buttonName: string;
|
||||
|
||||
if (standardButtonPressed) {
|
||||
buttonDOM = standardButtonPressed;
|
||||
@ -46,11 +46,29 @@ class PhysicalKeyboard {
|
||||
return;
|
||||
}
|
||||
|
||||
if (buttonDOM) {
|
||||
buttonDOM.style.background =
|
||||
const applyButtonStyle = (buttonElement: HTMLElement) => {
|
||||
buttonElement.style.background =
|
||||
options.physicalKeyboardHighlightBgColor || "#dadce4";
|
||||
buttonDOM.style.color =
|
||||
buttonElement.style.color =
|
||||
options.physicalKeyboardHighlightTextColor || "black";
|
||||
}
|
||||
|
||||
if (buttonDOM) {
|
||||
if(Array.isArray(buttonDOM)){
|
||||
buttonDOM.forEach(buttonElement => applyButtonStyle(buttonElement));
|
||||
|
||||
// Even though we have an array of buttons, we just want to press one of them
|
||||
if (options.physicalKeyboardHighlightPress) {
|
||||
if (options.physicalKeyboardHighlightPressUsePointerEvents) {
|
||||
buttonDOM[0]?.onpointerdown();
|
||||
} else if (options.physicalKeyboardHighlightPressUseClick) {
|
||||
buttonDOM[0]?.click();
|
||||
} else {
|
||||
instance.handleButtonClicked(buttonName, event);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
applyButtonStyle(buttonDOM);
|
||||
|
||||
if (options.physicalKeyboardHighlightPress) {
|
||||
if (options.physicalKeyboardHighlightPressUsePointerEvents) {
|
||||
@ -62,6 +80,7 @@ class PhysicalKeyboard {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -74,12 +93,28 @@ class PhysicalKeyboard {
|
||||
instance.getButtonElement(buttonPressed) ||
|
||||
instance.getButtonElement(`{${buttonPressed}}`);
|
||||
|
||||
if (buttonDOM && buttonDOM.removeAttribute) {
|
||||
buttonDOM.removeAttribute("style");
|
||||
const applyButtonStyle = (buttonElement: HTMLElement) => {
|
||||
if(buttonElement.removeAttribute){
|
||||
buttonElement.removeAttribute("style");
|
||||
}
|
||||
};
|
||||
|
||||
if (buttonDOM) {
|
||||
if(Array.isArray(buttonDOM)){
|
||||
buttonDOM.forEach(buttonElement => applyButtonStyle(buttonElement));
|
||||
|
||||
// Even though we have an array of buttons, we just want to press one of them
|
||||
if (options.physicalKeyboardHighlightPressUsePointerEvents) {
|
||||
buttonDOM[0]?.onpointerup();
|
||||
}
|
||||
} else {
|
||||
applyButtonStyle(buttonDOM);
|
||||
|
||||
if (options.physicalKeyboardHighlightPressUsePointerEvents) {
|
||||
buttonDOM.onpointerup();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user