Skip to content

Commit

Permalink
fixup! fix(useArrowNavigation): detach navigation from using class se…
Browse files Browse the repository at this point in the history
…lector

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Mar 26, 2024
1 parent bc2edb2 commit 6d131e2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/composables/useArrowNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ export function useArrowNavigation(listElementRef, defaultElementRef, options =
const focusedIndex = ref(null)
const isConfirmationEnabled = ref(null)

const lookupParentNavId = (childElement) => {
const lookupNavId = (element) => {
if (element.hasAttribute('data-nav-id')) {
return element.getAttribute('data-nav-id')
}
// Find parent element with data-nav-id attribute
let parentElement = childElement.parentNode
let parentElement = element.parentNode
while (parentElement && parentElement !== document.body) {
if (parentElement.hasAttribute('data-nav-id')) {
return parentElement.getAttribute('data-nav-id')
Expand All @@ -69,7 +72,7 @@ export function useArrowNavigation(listElementRef, defaultElementRef, options =

// Set focused index according to selected element
const handleFocusEvent = (event) => {
const newIndex = itemElementsIdMap.value.indexOf(lookupParentNavId(event.target))
const newIndex = itemElementsIdMap.value.indexOf(lookupNavId(event.target))
// Quit if triggered by arrow navigation as already handled
// or if using Tab key to navigate, and going through NcActions
if (focusedIndex.value !== newIndex && newIndex !== -1) {
Expand Down Expand Up @@ -142,6 +145,7 @@ export function useArrowNavigation(listElementRef, defaultElementRef, options =

if (itemElement.matches(focusableCondition)) {
itemElement.focus()
return
}

try {
Expand Down

0 comments on commit 6d131e2

Please sign in to comment.