make button focus a little more situational

This commit is contained in:
2026-01-02 18:03:23 -08:00
parent f17d48030c
commit 7595ddeaa3

View File

@ -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) => {