From 51e4a3b14bf0cce77071d459caf2dda3161ac0b3 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 22 Nov 2024 13:17:05 -0500 Subject: [PATCH] Don't trigger keyboard shortcuts if modifiers are held None of these keyboard shortcuts expect modifier keys, so they should in fact expect the absence of modifiers. --- src/useCallViewKeyboardShortcuts.test.tsx | 10 ++++++++++ src/useCallViewKeyboardShortcuts.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/useCallViewKeyboardShortcuts.test.tsx b/src/useCallViewKeyboardShortcuts.test.tsx index 9b8d45e7..fdf7ed85 100644 --- a/src/useCallViewKeyboardShortcuts.test.tsx +++ b/src/useCallViewKeyboardShortcuts.test.tsx @@ -93,6 +93,16 @@ test("reactions can be sent via keyboard presses", async () => { } }); +test("reaction is not sent when modifier key is held", async () => { + const user = userEvent.setup(); + + const sendReaction = vi.fn(); + render(); + + await user.keyboard("{Meta>}1{/Meta}"); + expect(sendReaction).not.toHaveBeenCalled(); +}); + test("raised hand can be sent via keyboard presses", async () => { const user = userEvent.setup(); diff --git a/src/useCallViewKeyboardShortcuts.ts b/src/useCallViewKeyboardShortcuts.ts index 7c27e1e2..77028a27 100644 --- a/src/useCallViewKeyboardShortcuts.ts +++ b/src/useCallViewKeyboardShortcuts.ts @@ -43,6 +43,8 @@ export function useCallViewKeyboardShortcuts( (event: KeyboardEvent) => { if (focusElement.current === null) return; if (!mayReceiveKeyEvents(focusElement.current)) return; + if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) + return; if (event.key === "m") { event.preventDefault();