refactor(use-key-press): handle modifier keys + inputs

This commit is contained in:
moklick
2023-02-13 13:48:26 +01:00
parent 0dc307769f
commit 7e6f5be656
+3 -8
View File
@@ -103,17 +103,12 @@ export function isInputDOMNode(event: KeyboardEvent | ReactKeyboardEvent): boole
// using composed path for handling shadow dom
const target = (kbEvent.composedPath?.()?.[0] || event.target) as HTMLElement;
const isInput = ['INPUT', 'SELECT', 'TEXTAREA'].includes(target?.nodeName) || target?.hasAttribute('contenteditable');
// we want to be able to do a multi selection event if we are in an input field
if (event.ctrlKey || event.metaKey || event.shiftKey) {
return false;
}
const isModifierKey = event.ctrlKey || event.metaKey || event.shiftKey;
// when an input field is focused we don't want to trigger deletion or movement of nodes
return (
['INPUT', 'SELECT', 'TEXTAREA'].includes(target?.nodeName) ||
target?.hasAttribute('contenteditable') ||
!!target?.closest('.nokey')
);
return (isInput && !isModifierKey) || !!target?.closest('.nokey');
}
export const isMouseEvent = (