mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
add keyboard shortcut and aria attribute to menu button
This commit is contained in:
parent
bd573957e0
commit
6eac968083
4 changed files with 53 additions and 37 deletions
|
@ -25,10 +25,46 @@ function onAuxClick(selector, callback, noPreventDefault) {
|
|||
});
|
||||
}
|
||||
|
||||
// make logo element as button on mobile layout
|
||||
function checkMenuToggleModeByLayout() {
|
||||
const logoElement = document.querySelector(".logo");
|
||||
const homePageLinkElement = document.querySelector(".logo > a")
|
||||
if (!logoElement) return
|
||||
const logoToggleButtonLabel = logoElement.getAttribute("data-toggle-button-label")
|
||||
|
||||
const navMenuElement = document.getElementById("header-menu");
|
||||
const navMenuElementIsExpanded = navMenuElement.classList.contains("js-menu-show")
|
||||
|
||||
if (document.documentElement.clientWidth < 620) {
|
||||
logoElement.setAttribute("role", "button");
|
||||
logoElement.setAttribute("tabindex", "0");
|
||||
logoElement.setAttribute("aria-label", logoToggleButtonLabel)
|
||||
if (navMenuElementIsExpanded) {
|
||||
logoElement.setAttribute("aria-expanded", "true")
|
||||
} else {
|
||||
logoElement.setAttribute("aria-expanded", "false")
|
||||
}
|
||||
homePageLinkElement.setAttribute("tabindex", "-1")
|
||||
} else {
|
||||
logoElement.removeAttribute("role");
|
||||
logoElement.removeAttribute("tabindex");
|
||||
logoElement.removeAttribute("aria-expanded");
|
||||
logoElement.removeAttribute("aria-label")
|
||||
homePageLinkElement.removeAttribute("tabindex");
|
||||
}
|
||||
}
|
||||
|
||||
// Show and hide the main menu on mobile devices.
|
||||
function toggleMainMenu() {
|
||||
function toggleMainMenu(event) {
|
||||
if (event.type === "keydown" && !(event.key === "Enter" || event.key === " ")) {
|
||||
return
|
||||
}
|
||||
if (event.currentTarget.getAttribute("role")) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
let menu = document.querySelector(".header nav ul");
|
||||
let menuToggleButton = document.querySelector(".header button[aria-controls='header-menu']");
|
||||
let menuToggleButton = document.querySelector(".logo");
|
||||
if (menu.classList.contains("js-menu-show")) {
|
||||
menu.classList.remove("js-menu-show")
|
||||
menuToggleButton.setAttribute("aria-expanded", false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue