|
@@ -15,17 +15,18 @@ export function useArrowKeysNavigation(searchItems: any, options: any = {}) {
|
|
|
const itemsLength = searchItems.value.length
|
|
const itemsLength = searchItems.value.length
|
|
|
const lastItemIndex = itemsLength - 1
|
|
const lastItemIndex = itemsLength - 1
|
|
|
const itemIndexValue = itemIndex.value
|
|
const itemIndexValue = itemIndex.value
|
|
|
- const action = searchItems.value[itemIndexValue].action
|
|
|
|
|
|
|
+ const action = searchItems.value[itemIndexValue]?.action
|
|
|
|
|
|
|
|
if (action && event.key === "Enter" && options.onEnter) {
|
|
if (action && event.key === "Enter" && options.onEnter) {
|
|
|
options.onEnter(action)
|
|
options.onEnter(action)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (event.key === "ArrowDown") {
|
|
|
|
|
|
|
+ if (itemsLength && event.key === "ArrowDown") {
|
|
|
itemIndex.value = itemIndexValue < lastItemIndex ? itemIndexValue + 1 : 0
|
|
itemIndex.value = itemIndexValue < lastItemIndex ? itemIndexValue + 1 : 0
|
|
|
} else if (itemIndexValue === 0) itemIndex.value = lastItemIndex
|
|
} else if (itemIndexValue === 0) itemIndex.value = lastItemIndex
|
|
|
- else if (event.key === "ArrowUp") itemIndex.value = itemIndexValue - 1
|
|
|
|
|
|
|
+ else if (itemsLength && event.key === "ArrowUp")
|
|
|
|
|
+ itemIndex.value = itemIndexValue - 1
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const preventPropagation = options && options.stopPropagation
|
|
const preventPropagation = options && options.stopPropagation
|