Adjust physicalKeyboardHighlightPreventDefault per #1841

This commit is contained in:
Francisco Hodge 2023-01-16 19:04:05 -05:00
parent f6a72b27b2
commit 65a506a2a4
2 changed files with 10 additions and 4 deletions

View File

@ -1094,11 +1094,13 @@ class SimpleKeyboard {
console.log(`Caret handling started (${this.keyboardDOMClass})`);
}
const { physicalKeyboardHighlightPreventDefault = false } = this.options;
/**
* Event Listeners
*/
document.addEventListener("keyup", this.handleKeyUp);
document.addEventListener("keydown", this.handleKeyDown);
document.addEventListener("keyup", this.handleKeyUp, physicalKeyboardHighlightPreventDefault);
document.addEventListener("keydown", this.handleKeyDown, physicalKeyboardHighlightPreventDefault);
document.addEventListener("mouseup", this.handleMouseUp);
document.addEventListener("touchend", this.handleTouchEnd);
document.addEventListener("select", this.handleSelect);
@ -1268,11 +1270,13 @@ class SimpleKeyboard {
`Destroying simple-keyboard instance: ${this.currentInstanceName}`
);
const { physicalKeyboardHighlightPreventDefault = false } = this.options;
/**
* Remove document listeners
*/
document.removeEventListener("keyup", this.handleKeyUp);
document.removeEventListener("keydown", this.handleKeyDown);
document.removeEventListener("keyup", this.handleKeyUp, physicalKeyboardHighlightPreventDefault);
document.removeEventListener("keydown", this.handleKeyDown, physicalKeyboardHighlightPreventDefault);
document.removeEventListener("mouseup", this.handleMouseUp);
document.removeEventListener("touchend", this.handleTouchEnd);
document.removeEventListener("select", this.handleSelect);

View File

@ -29,6 +29,7 @@ class PhysicalKeyboard {
if(options.physicalKeyboardHighlightPreventDefault){
event.preventDefault();
event.stopImmediatePropagation();
}
const buttonPressed = this.getSimpleKeyboardLayoutKey(event);
@ -94,6 +95,7 @@ class PhysicalKeyboard {
if(options.physicalKeyboardHighlightPreventDefault){
event.preventDefault();
event.stopImmediatePropagation();
}
const buttonPressed = this.getSimpleKeyboardLayoutKey(event);