Skip to content

Commit 14f36e9

Browse files
notriddleJoshua Nelson
authored and
Joshua Nelson
committed
Add descriptive comment for the space behaviour
1 parent 49c218e commit 14f36e9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

static/menu.js

+22
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,28 @@
140140
// space closes the menu, and activates the current link
141141
// this behavior is identical between both the WAI example, and GitHub's
142142
if (document.activeElement instanceof HTMLAnchorElement && !document.activeElement.hasAttribute("aria-haspopup")) {
143+
// It's supposed to copy the behaviour of the WAI Menu Bar
144+
// page, and of GitHub's menus. I've been using these two
145+
// sources to judge what is basically "industry standard"
146+
// behaviour for menu keyboard activity on the web.
147+
//
148+
// On GitHub, here's what I notice:
149+
//
150+
// 1 If you click open a menu, the menu button remains
151+
// focused. If, in this stage, I press space, the menu will
152+
// close.
153+
//
154+
// 2 If I use the arrow keys to focus a menu item, and then
155+
// press space, the menu item will be activated. For
156+
// example, clicking "+", then pressing down, then pressing
157+
// space will open the New Repository page.
158+
//
159+
// Behaviour 1 is why the
160+
// `!document.activeElement.hasAttribute("aria-haspopup")`
161+
// condition is there. It's to make sure the menu-link on
162+
// things like the About dropdown don't get activated.
163+
// Behaviour 2 is why this code is required at all; I want to
164+
// activate the currently highlighted menu item.
143165
document.activeElement.click();
144166
}
145167
setTimeout(function() {

0 commit comments

Comments
 (0)