Skip to content

Commit 2fdeb4e

Browse files
committed
Do not scroll when closing the menu with space
Fixes #1082
1 parent f6fd6cf commit 2fdeb4e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

static/menu.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,25 @@
128128
break;
129129
case "enter":
130130
case "return":
131+
// enter and return have the default browser behavior,
132+
// but they also close the menu
133+
// this behavior is identical between both the WAI example, and GitHub's
134+
setTimeout(function() {
135+
closeMenu();
136+
}, 100);
137+
break;
131138
case "space":
132139
case " ":
133-
// enter, return, and space have the default browser behavior,
134-
// but they also close the menu
140+
// space closes the menu, and activates the current link
135141
// this behavior is identical between both the WAI example, and GitHub's
142+
if (document.activeElement instanceof HTMLAnchorElement && !document.activeElement.hasAttribute("aria-haspopup")) {
143+
document.activeElement.click();
144+
}
136145
setTimeout(function() {
137146
closeMenu();
138147
}, 100);
148+
e.preventDefault();
149+
e.stopPropagation();
139150
break;
140151
case "home":
141152
case "pageup":

0 commit comments

Comments
 (0)