diff --git a/scripts/nav.js b/scripts/nav.js index ecdbb80..438cf47 100644 --- a/scripts/nav.js +++ b/scripts/nav.js @@ -86,9 +86,6 @@ const closeDropdown = function() { dropdownContent.classList.remove("show"); dropdownContent.setAttribute("aria-hidden", "true"); dropdownButton.setAttribute("aria-expanded", "false"); - - /* focus the button again */ - dropdownButton.focus(); } } @@ -104,6 +101,7 @@ dropdownButton.addEventListener("keydown", (event) => { openDropdown(); } else { closeDropdown(); + dropdownButton.focus(); } } }); @@ -112,6 +110,7 @@ firstDropdownItem.addEventListener("keydown", (event) => { if (event.key === "Tab" && event.shiftKey) { event.preventDefault(); closeDropdown(); + dropdownButton.focus(); } }); @@ -123,7 +122,10 @@ lastDropdownItem.addEventListener("keydown", (event) => { }); document.addEventListener("keydown", (event) => { - if (event.key === "Escape") closeDropdown(); + if (event.key === "Escape") { + closeDropdown(); + dropdownButton.focus(); + } }); window.addEventListener("click", (event) => {