Merge pull request #2838 from wbkd/refactor/use-key-press
refactor(use-key-press): handle modifier keys + inputs
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@reactflow/core': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
refactor: use key press handle modifier keys + input
|
||||||
@@ -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 = (
|
||||||
|
|||||||
Reference in New Issue
Block a user