Skip to content

Commit 569113a

Browse files
Properly handle escape key
The escape key should close everything at the current level and below, but not toggle the overall navigation menu itself.
1 parent c92a504 commit 569113a

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

asset/js/navigation.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,23 @@ function CatchEscape(e) {
7171
if (!(e.target.parentNode.parentNode instanceof HTMLUListElement)) {
7272
return;
7373
}
74-
ToggleMenu(e.target.parentNode.parentNode);
74+
75+
Initialize(e.target.parentNode.parentNode);
76+
}
77+
78+
// The initalize function will take a container and set all of the lists inside
79+
// to the initial state (collapsed).
80+
function Initialize(container) {
81+
let menus = container.getElementsByTagName('ul');
82+
$(menus).each(function(index, menu) {
83+
menu.setAttribute("hidden", "");
84+
menu.previousElementSibling.setAttribute("aria-expanded", "false");
85+
});
86+
// As long as we aren't at the top level, close the current container too.
87+
if (!(container.classList.contains("navigation"))) {
88+
container.setAttribute("hidden", "");
89+
container.previousElementSibling.setAttribute("aria-expanded", "false");
90+
}
7591
}
7692

7793
// The ToggleMenu function is how the navigation functions. It hides or shows

0 commit comments

Comments
 (0)