Skip to content

Commit 430a9da

Browse files
notriddleJoshua Nelson
authored andcommitted
Fix up PageUp / PageDn behavior in menus with many, many items
1 parent 10145f6 commit 430a9da

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

static/menu.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,43 @@
171171
e.stopPropagation();
172172
break;
173173
case "home":
174-
case "pageup":
175174
// home: focus first menu item.
176175
// This is the behavior of WAI, while GitHub scrolls,
177176
// but it's unlikely that a user will try to scroll the page while the menu is open,
178177
// so they won't do it on accident.
179178
switchTo = allItems[0];
180179
break;
181180
case "end":
182-
case "pagedown":
183181
// end: focus last menu item.
184182
// This is the behavior of WAI, while GitHub scrolls,
185183
// but it's unlikely that a user will try to scroll the page while the menu is open,
186184
// so they won't do it on accident.
187185
switchTo = last(allItems);
188186
break;
187+
case "pageup":
188+
// page up: jump five items up, stopping at the top
189+
// the number 5 is used so that we go one page in the
190+
// inner-scrolled Depedencies and Versions fields
191+
switchTo = currentLink;
192+
for (var n = 0; n < 5 && switchTo; ++n) {
193+
switchTo = previous(allItems, switchTo);
194+
}
195+
if (!switchTo) {
196+
switchTo = allItems[0];
197+
}
198+
break;
199+
case "pagedown":
200+
// page down: jump five items down, stopping at the bottom
201+
// the number 5 is used so that we go one page in the
202+
// inner-scrolled Depedencies and Versions fields
203+
switchTo = currentLink;
204+
for (var n = 0; n < 5 && switchTo; ++n) {
205+
switchTo = next(allItems, switchTo);
206+
}
207+
if (!switchTo) {
208+
switchTo = last(allItems);
209+
}
210+
break;
189211
}
190212
if (switchTo) {
191213
var switchToLink = switchTo.querySelector("a");

0 commit comments

Comments
 (0)