mirror of
https://github.com/immich-app/immich.git
synced 2025-11-24 17:30:43 +09:00
refactor(web): list navigation with keyboard (#7987)
This commit is contained in:
@@ -10,6 +10,7 @@ export type Shortcut = {
|
||||
|
||||
export type ShortcutOptions<T = HTMLElement> = {
|
||||
shortcut: Shortcut;
|
||||
ignoreInputFields?: boolean;
|
||||
onShortcut: (event: KeyboardEvent & { currentTarget: T }) => unknown;
|
||||
};
|
||||
|
||||
@@ -50,11 +51,13 @@ export const shortcuts = <T extends HTMLElement>(
|
||||
options: ShortcutOptions<T>[],
|
||||
): ActionReturn<ShortcutOptions<T>[]> => {
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
if (shouldIgnoreShortcut(event)) {
|
||||
return;
|
||||
}
|
||||
const ignoreShortcut = shouldIgnoreShortcut(event);
|
||||
|
||||
for (const { shortcut, onShortcut, ignoreInputFields = true } of options) {
|
||||
if (ignoreInputFields && ignoreShortcut) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const { shortcut, onShortcut } of options) {
|
||||
if (matchesShortcut(event, shortcut)) {
|
||||
event.preventDefault();
|
||||
onShortcut(event as KeyboardEvent & { currentTarget: T });
|
||||
|
||||
Reference in New Issue
Block a user