From 5dbbf9191b469c06121a70c4e30d3f28fce2464c Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 8 Mar 2024 23:47:46 +0300 Subject: [PATCH] fix disabled indexes check loop --- src/hooks/useArrowKeyFocusManager.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hooks/useArrowKeyFocusManager.ts b/src/hooks/useArrowKeyFocusManager.ts index 78ffc7f87209..458a39d91ca5 100644 --- a/src/hooks/useArrowKeyFocusManager.ts +++ b/src/hooks/useArrowKeyFocusManager.ts @@ -84,7 +84,10 @@ export default function useArrowKeyFocusManager({ while (disabledIndexes.includes(newFocusedIndex)) { newFocusedIndex -= allowHorizontalArrowKeys ? itemsPerRow : 1; if (newFocusedIndex < 0) { - break; + if (disableCyclicTraversal) { + break; + } + newFocusedIndex = maxIndex; } if (newFocusedIndex === currentFocusedIndex) { // all indexes are disabled @@ -127,8 +130,11 @@ export default function useArrowKeyFocusManager({ newFocusedIndex += allowHorizontalArrowKeys ? itemsPerRow : 1; } - if (newFocusedIndex < 0) { - break; + if (newFocusedIndex > maxIndex) { + if (disableCyclicTraversal) { + break; + } + newFocusedIndex = 0; } if (newFocusedIndex === currentFocusedIndex) { // all indexes are disabled