Skip to content

Commit ade643a

Browse files
smhigleymcking65
andcommitted
Listbox examples: Prevent default arrow key scroll only when moving focus in listbox (pull #1294)
Resolves #1249 by changing up and down arrow key handling in listbox. With this change, default scroll behavior is only prevented if focus is actually moved. This allows the up/down arrow keys to scroll the listbox to its upper and lower bounds. Co-authored-by: Matt King <[email protected]>
1 parent eec5af6 commit ade643a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

examples/listbox/js/listbox.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ aria.Listbox.prototype.checkKeyPress = function (evt) {
110110
break;
111111
case aria.KeyCode.UP:
112112
case aria.KeyCode.DOWN:
113-
evt.preventDefault();
114113

115114
if (!this.activeDescendant) {
116115
// focus first option if no option was previously focused, and perform no other actions
@@ -119,6 +118,7 @@ aria.Listbox.prototype.checkKeyPress = function (evt) {
119118
}
120119

121120
if (this.moveUpDownEnabled && evt.altKey) {
121+
evt.preventDefault();
122122
if (key === aria.KeyCode.UP) {
123123
this.moveUpItems();
124124
}
@@ -137,6 +137,7 @@ aria.Listbox.prototype.checkKeyPress = function (evt) {
137137

138138
if (nextItem) {
139139
this.focusItem(nextItem);
140+
evt.preventDefault();
140141
}
141142

142143
break;

0 commit comments

Comments
 (0)