Skip to content

Commit

Permalink
APP-3126: fix searchable select value and focus issues (viamrobotics#459
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mcous authored Jan 5, 2024
1 parent 2614e92 commit 2468474
Show file tree
Hide file tree
Showing 9 changed files with 669 additions and 400 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/prime-core",
"version": "0.0.76",
"version": "0.0.77",
"publishConfig": {
"access": "public"
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export {
type TooltipVisibility,
} from './tooltip';

export * from './keyboard';
export { useTimeout } from './use-timeout';
export { uniqueId } from './unique-id';
export { default as VectorInput } from './vector-input.svelte';
26 changes: 26 additions & 0 deletions packages/core/src/lib/keyboard.ts
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();
}
}
};
};
Loading

0 comments on commit 2468474

Please sign in to comment.