From bbd7af2da7ebf413bdd292365edeb4d92c15517d Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 26 Oct 2021 20:06:34 -0400 Subject: [PATCH] fix: out of bound index (#99) --- src/KBarResults.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/KBarResults.tsx b/src/KBarResults.tsx index 2d43775..1b6c6b1 100644 --- a/src/KBarResults.tsx +++ b/src/KBarResults.tsx @@ -46,6 +46,7 @@ const KBarResults: React.FC = (props) => { let nextIndex = index > START_INDEX ? index - 1 : index; // avoid setting active index on a group if (typeof itemsRef.current[nextIndex] === "string") { + if (nextIndex === 0) return index; nextIndex -= 1; } return nextIndex; @@ -60,6 +61,7 @@ const KBarResults: React.FC = (props) => { index < itemsRef.current.length - 1 ? index + 1 : index; // avoid setting active index on a group if (typeof itemsRef.current[nextIndex] === "string") { + if (nextIndex === itemsRef.current.length - 1) return index; nextIndex += 1; } return nextIndex;