From 0891b83d7b89c2a3c9f39e0597307787dc4f1b91 Mon Sep 17 00:00:00 2001 From: moklick Date: Wed, 14 Sep 2022 14:30:10 +0200 Subject: [PATCH] chore(isInputDOMNode): add event.target as fallback --- src/hooks/useKeyPress.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hooks/useKeyPress.ts b/src/hooks/useKeyPress.ts index 8ac7dcf8..6b164556 100644 --- a/src/hooks/useKeyPress.ts +++ b/src/hooks/useKeyPress.ts @@ -108,7 +108,8 @@ function useKeyOrCode(eventCode: string, keysToWatch: KeyCode): KeyOrCode { } function isInputDOMNode(event: KeyboardEvent): boolean { - const target = event.composedPath()[0] as HTMLElement; + // using composed path for handling shadow dom + const target = (event.composedPath?.()[0] || event.target) as HTMLElement; return ['INPUT', 'SELECT', 'TEXTAREA'].includes(target?.nodeName) || target?.hasAttribute('contenteditable'); }