refactor: list keyboard navigation
This commit is contained in:
@@ -23,7 +23,7 @@ export const useListKeyboardNavigation = (containerElement: HTMLElement | null,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
listItems.current = Array.from(containerElement.querySelectorAll('button, div[role="button"]'))
|
listItems.current = Array.from(containerElement.querySelectorAll('button, div[role="button"]'))
|
||||||
if (listItems.current.length > 0) {
|
if (listItems.current[0]) {
|
||||||
listItems.current[0].tabIndex = 0
|
listItems.current[0].tabIndex = 0
|
||||||
}
|
}
|
||||||
}, [containerElement])
|
}, [containerElement])
|
||||||
@@ -73,7 +73,9 @@ export const useListKeyboardNavigation = (containerElement: HTMLElement | null,
|
|||||||
if (containerElement) {
|
if (containerElement) {
|
||||||
containerElement.tabIndex = FOCUSABLE_BUT_NOT_TABBABLE
|
containerElement.tabIndex = FOCUSABLE_BUT_NOT_TABBABLE
|
||||||
setLatestListItems()
|
setLatestListItems()
|
||||||
listItems.current[0].tabIndex = 0
|
if (listItems.current[0]) {
|
||||||
|
listItems.current[0].tabIndex = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [containerElement, setLatestListItems])
|
}, [containerElement, setLatestListItems])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user