From 02fd34ec3269d95460d457cdde01b062db43908b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20V=C3=ADtor=20Ribeiro=20Martins?= Date: Thu, 6 Jul 2023 19:39:59 -0300 Subject: [PATCH] feat: set modifiersKey to be alt, meta, crtl and tab --- packages/ui/src/components/Command/Command.utils.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/ui/src/components/Command/Command.utils.tsx b/packages/ui/src/components/Command/Command.utils.tsx index 809b4273c7c..8bff8b8d96d 100644 --- a/packages/ui/src/components/Command/Command.utils.tsx +++ b/packages/ui/src/components/Command/Command.utils.tsx @@ -408,8 +408,10 @@ export function useAutoInputFocus() { // Focus the input when typing from anywhere React.useEffect(() => { - function isModifierNotShift(event: KeyboardEvent) { - return event.key.length !== 1 && event.key !== 'Shift' + function isModifierKey(event: KeyboardEvent) { + const modifierKeys = ['Alt', 'Control', 'Meta', 'Tab'] + const { key } = event + return modifierKeys.includes(key) } // Keep track of whether the modifier key (except shift) is pressed @@ -417,7 +419,7 @@ export function useAutoInputFocus() { function onKeyDown(event: KeyboardEvent) { // If the user is typing a modifier key, don't focus the input and set the modifierPressed flag - if (isModifierNotShift(event)) { + if (isModifierKey(event)) { modifierPressed = true } else { if (!modifierPressed) { @@ -428,7 +430,7 @@ export function useAutoInputFocus() { } function onKeyUp(event: KeyboardEvent) { console.log('keyup') - if (isModifierNotShift(event)) { + if (isModifierKey(event)) { // Reset the modifierPressed flag when the modifier key is released modifierPressed = false }