mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-22 08:01:00 +00:00
Further simplify post-route handler.
* Use `HtmlElement.tabIndex` directly rather than going through attributes. * Always restore `tabIndex` after focus. * Remove `setTimeout` to simplify implementation. This does have a disadvantage in that it leaves unnecessary `tabindex="1"` instances around. On the other hand, it does simplify the implementation and get the job done' so is probably a more clear example of how to do this correctly.
This commit is contained in:
parent
7d09845b8c
commit
7b48c2fbaf
1 changed files with 3 additions and 9 deletions
|
@ -180,16 +180,10 @@ let liveSocket = new LiveSocket("/live", Socket, {
|
||||||
let routeUpdated = () => {
|
let routeUpdated = () => {
|
||||||
let target = document.querySelector("main h1") || document.querySelector("main")
|
let target = document.querySelector("main h1") || document.querySelector("main")
|
||||||
if (target) {
|
if (target) {
|
||||||
let origTabIndex = target.getAttribute("tabindex")
|
let origTabIndex = target.tabIndex
|
||||||
target.setAttribute("tabindex", "-1")
|
target.tabIndex = -1
|
||||||
target.focus()
|
target.focus()
|
||||||
window.setTimeout(() => {
|
target.tabIndex = origTabIndex
|
||||||
if (origTabIndex) {
|
|
||||||
target.setAttribute("tabindex", origTabIndex)
|
|
||||||
} else {
|
|
||||||
target.removeAttribute("tabindex")
|
|
||||||
}
|
|
||||||
}, 1000)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue