forked from viamrobotics/prime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APP-3126: fix searchable select value and focus issues (viamrobotics#459
- Loading branch information
Showing
9 changed files
with
669 additions
and
400 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
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export type KeyMap = Partial<Record<string, KeyEventHandler | KeyOptions>>; | ||
|
||
export type KeyEventHandler = (event: KeyboardEvent) => unknown; | ||
|
||
export interface KeyOptions { | ||
handler: KeyEventHandler; | ||
preventDefault?: boolean; | ||
} | ||
|
||
export const createHandleKey = (keyMap: KeyMap) => { | ||
return (event: KeyboardEvent): void => { | ||
const options = keyMap[event.key]; | ||
const handler = typeof options === 'function' ? options : options?.handler; | ||
const preventDefault = | ||
typeof options === 'object' ? options.preventDefault : true; | ||
|
||
if (typeof handler === 'function') { | ||
handler(event); | ||
|
||
if (preventDefault) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
} | ||
}; | ||
}; |
Oops, something went wrong.