From 7595ddeaa35faa6d3d5f9106094b834a04e2cbed Mon Sep 17 00:00:00 2001 From: Lee Cattarin Date: Fri, 2 Jan 2026 18:03:23 -0800 Subject: [PATCH] make button focus a little more situational --- scripts/nav.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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) => {