(focusable) focus and unfocus with typescript

This commit is contained in:
Julien Calixte
2023-07-08 23:58:39 +02:00
parent 8aaf4f5d7a
commit e67541a64b
3 changed files with 24 additions and 4 deletions

16
main.ts
View File

@@ -18,3 +18,19 @@ if (size === "small") {
body.style.fontSize = "15px"
}
}
const focusElements = params.getAll("focus")
if (focusElements.length >= 0) {
const focusables = document.querySelectorAll(".focusable")
focusables.forEach((focusable) => {
const elementToFocus = focusElements.some((element) =>
focusable.classList.contains(element)
)
if (!elementToFocus) {
focusable.classList.add("no-focus")
}
})
}