Merge pull request #2838 from wbkd/refactor/use-key-press

refactor(use-key-press): handle modifier keys + inputs
This commit is contained in:
Moritz Klack
2023-02-13 13:50:05 +01:00
committed by GitHub
2 changed files with 8 additions and 8 deletions

View File

@@ -0,0 +1,5 @@
---
'@reactflow/core': patch
---
refactor: use key press handle modifier keys + input

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 = (