mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-21 15:41: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 target = document.querySelector("main h1") || document.querySelector("main")
|
||||
if (target) {
|
||||
let origTabIndex = target.getAttribute("tabindex")
|
||||
target.setAttribute("tabindex", "-1")
|
||||
let origTabIndex = target.tabIndex
|
||||
target.tabIndex = -1
|
||||
target.focus()
|
||||
window.setTimeout(() => {
|
||||
if (origTabIndex) {
|
||||
target.setAttribute("tabindex", origTabIndex)
|
||||
} else {
|
||||
target.removeAttribute("tabindex")
|
||||
}
|
||||
}, 1000)
|
||||
target.tabIndex = origTabIndex
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue