Skip to content

Commit

Permalink
🪲 Fix isEventTargetUsingKeyEvent logic
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed Sep 7, 2023
1 parent cbd73a5 commit 762a81c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/use-keyboard-events/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ export const usesKeyEvents = (target: EventTarget) =>
(target as HTMLElement).tagName === 'INPUT';

export const isEventTargetUsingKeyEvent = (event: KeyboardEvent) => {
if (!event.target) return false;
const target = event.target as HTMLElement;
if (!usesKeyEvents(target) || target.tagName !== 'INPUT') return false;
if (!target || !usesKeyEvents(target)) return false;
// Restrict special handling to only non-text <input> elements
if (target.tagName !== 'INPUT') return true;
if (!NON_TEXT_INPUT_TYPES.has((target as HTMLInputElement).type)) return true;
// Non-text inputs can use arrow keys, escape, the spacebar, and return / enter
if (NON_TEXT_INPUT_TYPES.has((target as HTMLInputElement).type)) {
return NON_TEXT_INPUT_USES_KEYS.has(event.key);
}
return true;
return NON_TEXT_INPUT_USES_KEYS.has(event.key);
};

function handleKeyboardEvent(event: KeyboardEvent) {
Expand Down

0 comments on commit 762a81c

Please sign in to comment.