From 6ac386351a99a42aef6f3c866fccd011ba87c881 Mon Sep 17 00:00:00 2001 From: m-shaka Date: Fri, 27 Sep 2024 08:20:43 +0900 Subject: [PATCH] fix: wrong focus when `hotkey` is an empty array (#2491) Co-authored-by: Chance Strickland --- packages/react/toast/src/Toast.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react/toast/src/Toast.tsx b/packages/react/toast/src/Toast.tsx index af7f36aa28..0eebdaeaaf 100644 --- a/packages/react/toast/src/Toast.tsx +++ b/packages/react/toast/src/Toast.tsx @@ -159,7 +159,8 @@ const ToastViewport = React.forwardRef const handleKeyDown = (event: KeyboardEvent) => { // we use `event.code` as it is consistent regardless of meta keys that were pressed. // for example, `event.key` for `Control+Alt+t` is `†` and `t !== †` - const isHotkeyPressed = hotkey.every((key) => (event as any)[key] || event.code === key); + const isHotkeyPressed = + hotkey.length !== 0 && hotkey.every((key) => (event as any)[key] || event.code === key); if (isHotkeyPressed) ref.current?.focus(); }; document.addEventListener('keydown', handleKeyDown);