From 28825bc2eee3f3bfed505635ea16b08049b950d7 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Fri, 2 Feb 2024 16:12:36 +0530 Subject: [PATCH] refactor: list keyboard navigation --- .../web/src/javascripts/Hooks/useListKeyboardNavigation.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/web/src/javascripts/Hooks/useListKeyboardNavigation.ts b/packages/web/src/javascripts/Hooks/useListKeyboardNavigation.ts index 2b65490c7..edb266938 100644 --- a/packages/web/src/javascripts/Hooks/useListKeyboardNavigation.ts +++ b/packages/web/src/javascripts/Hooks/useListKeyboardNavigation.ts @@ -23,7 +23,7 @@ export const useListKeyboardNavigation = (containerElement: HTMLElement | null, return } listItems.current = Array.from(containerElement.querySelectorAll('button, div[role="button"]')) - if (listItems.current.length > 0) { + if (listItems.current[0]) { listItems.current[0].tabIndex = 0 } }, [containerElement]) @@ -73,7 +73,9 @@ export const useListKeyboardNavigation = (containerElement: HTMLElement | null, if (containerElement) { containerElement.tabIndex = FOCUSABLE_BUT_NOT_TABBABLE setLatestListItems() - listItems.current[0].tabIndex = 0 + if (listItems.current[0]) { + listItems.current[0].tabIndex = 0 + } } }, [containerElement, setLatestListItems])