Skip to content

Commit 5d361fa

Browse files
committed
Only preventDefault and stopPropagation if the keybinding element is valid
1 parent e1b7ff2 commit 5d361fa

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/keybinding.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,14 @@ export default function Keybinding(props: KeybindingProps) {
5959

6060
const onKeyEvent = useCallback(
6161
(e: KeyboardEvent) => {
62-
// is actually a KeyboardEvent
63-
if (preventDefault) e.preventDefault();
64-
if (stopPropagation) e.stopPropagation();
65-
6662
const target = e.target as HTMLElement | null;
6763

68-
if (target) {
64+
if (target != null) {
6965
let canDispatch = true;
7066

7167
if (
7268
preventInputConflict &&
73-
TARGETS_BLACKLIST.indexOf(target.tagName.toLowerCase()) > -1
69+
TARGETS_BLACKLIST.includes(target.tagName.toLowerCase())
7470
) {
7571
canDispatch = false;
7672
}
@@ -79,7 +75,11 @@ export default function Keybinding(props: KeybindingProps) {
7975
canDispatch = false;
8076
}
8177

82-
if (canDispatch) onKey(e);
78+
if (canDispatch) {
79+
if (preventDefault) e.preventDefault();
80+
if (stopPropagation) e.stopPropagation();
81+
onKey(e);
82+
}
8383
}
8484
},
8585
[

0 commit comments

Comments
 (0)