fix(system): safely handles non-html-element object

`event.composedPath` and `event.target` do not always return `HTMLElement` object(as their types suggested).
This commit is contained in:
CRIMX
2024-12-09 19:08:49 +08:00
committed by GitHub
parent 1e1eb06f2a
commit 468699bfdd

View File

@@ -40,7 +40,7 @@ const inputTags = ['INPUT', 'SELECT', 'TEXTAREA'];
export function isInputDOMNode(event: KeyboardEvent): boolean {
// using composed path for handling shadow dom
const target = (event.composedPath?.()?.[0] || event.target) as HTMLElement;
const isInput = inputTags.includes(target?.nodeName) || target?.hasAttribute('contenteditable');
const isInput = inputTags.includes(target?.nodeName) || target?.hasAttribute?.('contenteditable');
// when an input field is focused we don't want to trigger deletion or movement of nodes
return isInput || !!target?.closest('.nokey');