make button focus a little more situational
This commit is contained in:
@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user