Skip to content

Commit

Permalink
Merge pull request #69 from baloise/feat/arrow-keys
Browse files Browse the repository at this point in the history
feat(utils): add more key event utils
  • Loading branch information
hirsch88 authored Sep 12, 2024
2 parents da20772 + a86fa69 commit bc4c117
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/utils/src/utils/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,31 @@ export function isArrowDownKey(event: KeyboardEvent): boolean {
export function isArrowUpKey(event: KeyboardEvent): boolean {
return event.key === 'ArrowUp' || event.key === 'Up'
}

/**
* Returns `true` if the keyboard event was triggered by the `ArrowLeft` key
*/
export function isArrowLeftKey(event: KeyboardEvent): boolean {
return event.key === 'ArrowLeft' || event.key === 'Left'
}

/**
* Returns `true` if the keyboard event was triggered by the `ArrowRight` key
*/
export function isArrowRightKey(event: KeyboardEvent): boolean {
return event.key === 'ArrowRight' || event.key === 'Right'
}

/**
* Returns `true` if the keyboard event was triggered by the `Home` key
*/
export function isHomeKey(event: KeyboardEvent): boolean {
return event.key === 'Home'
}

/**
* Returns `true` if the keyboard event was triggered by the `End` key
*/
export function isEndKey(event: KeyboardEvent): boolean {
return event.key === 'End'
}

0 comments on commit bc4c117

Please sign in to comment.