Skip to content

Commit f71d708

Browse files
committed
Allow the user to open the Crate Page from the crate dropdown
This fixes a regression added by the keyboard-accessible JavaScript menus, where clicking the link opened the menu instead of the linked page. It checks if the link points somewhere, and lets it behave normally if it does. Also adds keyboard handling for the space key, so you can still get to the menu.
1 parent fb236ac commit f71d708

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

templates/menu.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
backdrop.style.display = "block";
4040
}
4141
function menuOnClick(e) {
42+
if (this.getAttribute("href") != "#") {
43+
return;
44+
}
4245
if (this.parentNode === currentMenu) {
4346
closeMenu();
4447
} else {
@@ -123,6 +126,7 @@
123126
case "enter":
124127
case "return":
125128
case "space":
129+
case " ":
126130
// enter, return, and space have the default browser behavior,
127131
// but they also close the menu
128132
// this behavior is identical between both the WAI example, and GitHub's
@@ -155,6 +159,17 @@
155159
e.preventDefault();
156160
e.stopPropagation();
157161
}
162+
} else if (e.target.parentNode.className && e.target.parentNode.className.indexOf("pure-menu-has-children") !== -1) {
163+
switch (e.key.toLowerCase()) {
164+
case "arrowdown":
165+
case "down":
166+
case "space":
167+
case " ":
168+
openMenu(e.target.parentNode);
169+
e.preventDefault();
170+
e.stopPropagation();
171+
break;
172+
}
158173
}
159174
};
160175
var menus = Array.prototype.slice.call(document.querySelectorAll(".pure-menu-has-children"));

0 commit comments

Comments
 (0)