Fixed odd behavior in navigation tab behavior

This commit is contained in:
squidfunk
2018-01-11 21:47:16 +01:00
committed by Martin Donath
parent 7a0c464ed6
commit 3217754daa
6 changed files with 33 additions and 8 deletions

View File

@@ -298,6 +298,31 @@ function initialize(config) { // eslint-disable-line func-style
})
})).listen()
/* Listener: handle tabbing context for better accessibility */
new Material.Event.Listener(document.body, "keydown", ev => {
if (ev.keyCode === 9) {
const labels = document.querySelectorAll(
"[data-md-component=navigation] .md-nav__link[for]:not([tabindex])")
Array.prototype.forEach.call(labels, label => {
label.tabIndex = 0
})
}
}).listen()
/* Listener: reset tabbing behavior */
new Material.Event.Listener(document.body, "click", () => {
const labels = document.querySelectorAll(
"[data-md-component=navigation] .md-nav__link[tabindex]")
Array.prototype.forEach.call(labels, label => {
label.removeAttribute("tabIndex")
})
}).listen()
document.body.addEventListener("click", () => {
if (document.body.dataset.mdState === "tabbing")
document.body.dataset.mdState = ""
})
/* Listener: close drawer when anchor links are clicked */
new Material.Event.MatchMedia("(max-width: 959px)",
new Material.Event.Listener("[data-md-component=navigation] [href^='#']",