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
+5
View File
@@ -0,0 +1,5 @@
---
'@reactflow/core': patch
---
refactor: use key press handle modifier keys + input
+3 -8
View File
@@ -103,17 +103,12 @@ export function isInputDOMNode(event: KeyboardEvent | ReactKeyboardEvent): boole
// using composed path for handling shadow dom // using composed path for handling shadow dom
const target = (kbEvent.composedPath?.()?.[0] || event.target) as HTMLElement; 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 // 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) { const isModifierKey = event.ctrlKey || event.metaKey || event.shiftKey;
return false;
}
// when an input field is focused we don't want to trigger deletion or movement of nodes // when an input field is focused we don't want to trigger deletion or movement of nodes
return ( return (isInput && !isModifierKey) || !!target?.closest('.nokey');
['INPUT', 'SELECT', 'TEXTAREA'].includes(target?.nodeName) ||
target?.hasAttribute('contenteditable') ||
!!target?.closest('.nokey')
);
} }
export const isMouseEvent = ( export const isMouseEvent = (