Skip to content

Commit

Permalink
fix: dont rely on document prop in useKey handler (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbach committed May 2, 2023
1 parent d2ae8f5 commit 2c7d8bc
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/core/src/hotkeys/useKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ export const useKey = (
onHit: (e: KeyboardEvent) => void,
active?: boolean
) => {
useHtmlElementEventListener(document, 'keydown', e => {
if (!active) {
return;
}
useHtmlElementEventListener(
typeof document !== 'undefined' ? document : undefined,
'keydown',
e => {
if (!active) {
return;
}

if (active && key.toLowerCase() === e.key.toLowerCase()) {
onHit(e);
if (active && key.toLowerCase() === e.key.toLowerCase()) {
onHit(e);
}
}
});
);
};

0 comments on commit 2c7d8bc

Please sign in to comment.