From 65a506a2a48bcbd3ff5e2df4a568fbc6d92f9d28 Mon Sep 17 00:00:00 2001 From: Francisco Hodge Date: Mon, 16 Jan 2023 19:04:05 -0500 Subject: [PATCH] Adjust physicalKeyboardHighlightPreventDefault per #1841 --- src/lib/components/Keyboard.ts | 12 ++++++++---- src/lib/services/PhysicalKeyboard.ts | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/components/Keyboard.ts b/src/lib/components/Keyboard.ts index fc6b773e..94142f5e 100644 --- a/src/lib/components/Keyboard.ts +++ b/src/lib/components/Keyboard.ts @@ -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); diff --git a/src/lib/services/PhysicalKeyboard.ts b/src/lib/services/PhysicalKeyboard.ts index 9978ac34..1488afe2 100644 --- a/src/lib/services/PhysicalKeyboard.ts +++ b/src/lib/services/PhysicalKeyboard.ts @@ -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);