chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2024-10-19 14:44:55 +02:00
parent c9ce29f206
commit 40e894df8b
294 changed files with 14209 additions and 4192 deletions

View file

@ -1,10 +1,14 @@
export function focusWithArrows(htmlElement: HTMLDivElement, classname: string) {
const destroy: () => void = undefined
htmlElement.addEventListener("keyup", e => {
htmlElement.addEventListener("keyup", (e) => {
const currentElement = document.activeElement
const canBeSelected = <HTMLElement[]> Array.from(htmlElement.getElementsByClassName(classname))
const canBeSelected = <HTMLElement[]>(
Array.from(htmlElement.getElementsByClassName(classname))
)
const i = canBeSelected.findIndex(el => el.contains(currentElement) || el === currentElement)
const i = canBeSelected.findIndex(
(el) => el.contains(currentElement) || el === currentElement
)
const l = canBeSelected.length
if (e.key === "ArrowDown") {
canBeSelected.at((i + 1) % l).focus()
@ -12,10 +16,9 @@ export function focusWithArrows(htmlElement: HTMLDivElement, classname: string)
}
if (e.key === "ArrowUp") {
canBeSelected.at((i - 1) ).focus()
canBeSelected.at(i - 1).focus()
return
}
})
return { destroy }
}