Skip to content

Commit d195ea6

Browse files
committed
Better focus behaviour on menu close
If they click the backdrop, give focus to the rustdoc container, and otherwise give the focus to the menu button itself.
1 parent f71d708 commit d195ea6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

templates/menu.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
return allItems[allItems.length - 1];
2929
}
3030
function closeMenu() {
31+
if (this === backdrop) {
32+
var rustdoc = document.querySelector(".rustdoc");
33+
if (rustdoc) {
34+
rustdoc.focus();
35+
} else {
36+
document.documentElement.focus();
37+
}
38+
} else if (currentMenu.querySelector(".pure-menu-link:focus")) {
39+
currentMenu.firstElementChild.focus();
40+
}
3141
currentMenu.className = currentMenu.className.replace("pure-menu-active", "");
3242
currentMenu = null;
3343
backdrop.style.display = "none";
@@ -113,7 +123,6 @@
113123
// but is a rationalization of GitHub's behavior: we don't want users who know how to
114124
// use tab and enter, but don't know that they can close menus with Escape,
115125
// to find themselves completely trapped in the menu
116-
currentMenu.firstElementChild.focus();
117126
closeMenu();
118127
e.preventDefault();
119128
e.stopPropagation();

0 commit comments

Comments
 (0)