-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fa1d9c
commit e90df3f
Showing
2 changed files
with
18 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
/** | ||
* @param {(event: KeyboardEvent) => void} handler | ||
* @returns {(event: KeyboardEvent) => void} | ||
*/ | ||
export default function (handler) { | ||
export default (handler) => { | ||
return (event) => { | ||
if (event.code === 'Space' || event.code === 'Enter') { | ||
if (isEnter(event) || isSpace(event)) { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
handler(event) | ||
} | ||
} | ||
} | ||
|
||
/** @param {KeyboardEvent} event */ | ||
export const isSpace = (event) => event.code === 'Space' | ||
|
||
/** @param {KeyboardEvent} event */ | ||
export const isEnter = (event) => event.code === 'Enter' || event.key === 'Enter' // for mobile enter button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters