forked from MapComplete/MapComplete
More search functionality
This commit is contained in:
parent
5d0de8520b
commit
1c46a65c84
25 changed files with 962 additions and 846 deletions
21
src/Utils/focusWithArrows.ts
Normal file
21
src/Utils/focusWithArrows.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
export function focusWithArrows(htmlElement: HTMLDivElement, classname: string) {
|
||||
const destroy: () => void = undefined
|
||||
htmlElement.addEventListener("keyup", e => {
|
||||
const currentElement = document.activeElement
|
||||
const canBeSelected = <HTMLElement[]> Array.from(htmlElement.getElementsByClassName(classname))
|
||||
|
||||
const i = canBeSelected.findIndex(el => el.contains(currentElement) || el === currentElement)
|
||||
const l = canBeSelected.length
|
||||
if (e.key === "ArrowDown") {
|
||||
canBeSelected.at((i + 1) % l).focus()
|
||||
return
|
||||
}
|
||||
|
||||
if (e.key === "ArrowUp") {
|
||||
canBeSelected.at((i - 1) ).focus()
|
||||
return
|
||||
}
|
||||
})
|
||||
return { destroy }
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue