The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update use-keyboard-shortcut.tsx
Tim Wilson846b8bb37f59
diff --git a/packages/ui/src/hooks/use-keyboard-shortcut.tsx b/packages/ui/src/hooks/use-keyboard-shortcut.tsxindex da365e358f..7af0c1a99b 100644--- a/packages/ui/src/hooks/use-keyboard-shortcut.tsx+++ b/packages/ui/src/hooks/use-keyboard-shortcut.tsx@@ -15,6 +15,8 @@ type KeyboardShortcutListener = {key: string | string[];enabled?: boolean;priority?: number;+ modal?: boolean;+ sheet?: boolean;};export const KeyboardShortcutContext = createContext<{@@ -42,9 +44,9 @@ export function KeyboardShortcutProvider({export function useKeyboardShortcut(key: KeyboardShortcutListener["key"],callback: (e: KeyboardEvent) => void,- options: { modal?: boolean; sheet?: boolean } & Pick<+ options: Pick<KeyboardShortcutListener,- "enabled" | "priority"+ "enabled" | "priority" | "modal" | "sheet"> = {},) {const id = useId();@@ -53,6 +55,8 @@ export function useKeyboardShortcut(const onKeyDown = useCallback((e: KeyboardEvent) => {+ if (options.enabled === false) return;+const target = e.target as HTMLElement;const existingModalBackdrop = document.getElementById("modal-backdrop");const existingSheetBackdrop = document.querySelector(@@ -77,9 +81,13 @@ export function useKeyboardShortcut(const matchingListeners = listeners.filter((l) =>l.enabled !== false &&+ !!existingModalBackdrop === !!l.modal &&+ !!existingSheetBackdrop === !!l.sheet &&(Array.isArray(l.key) ? l.key.includes(e.key) : l.key === e.key),);+ console.log({ matchingListeners });+if (!matchingListeners.length) return;// Sort the listeners by priority@@ -94,7 +102,15 @@ export function useKeyboardShortcut(e.preventDefault();callback(e);},- [key, listeners, id, callback, options.modal, options.sheet],+ [+ key,+ listeners,+ id,+ callback,+ options.enabled,+ options.modal,+ options.sheet,+ ],);useEffect(() => {