Skip to content

Commit

Permalink
Combobox with Grid Popup Example: Fix arrow key wrapping in grid (pull
Browse files Browse the repository at this point in the history
…#530)

For issue #499, add additional check for row index so that LEFT/RIGHT arrow keys wrap to previous/next row.
  • Loading branch information
gerardkcohen authored and mcking65 committed Nov 20, 2017
1 parent 779db63 commit 691269e
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions examples/combobox/aria1.1pattern/js/grid-combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,32 @@ aria.GridCombobox.prototype.updateResults = function () {
}
};

aria.GridCombobox.prototype.getRowIndex = function (key) {
var activeRowIndex = this.activeRowIndex;

switch (key) {
case aria.KeyCode.UP:
case aria.KeyCode.LEFT:
if (activeRowIndex <= 0) {
activeRowIndex = this.rowsCount - 1;
}
else {
activeRowIndex--;
}
break;
case aria.KeyCode.DOWN:
case aria.KeyCode.RIGHT:
if (activeRowIndex === -1 || activeRowIndex >= this.rowsCount - 1) {
activeRowIndex = 0;
}
else {
activeRowIndex++;
}
}

return activeRowIndex;
};

aria.GridCombobox.prototype.setActiveItem = function (evt) {
var key = evt.which || evt.keyCode;
var activeRowIndex = this.activeRowIndex;
Expand Down Expand Up @@ -142,27 +168,18 @@ aria.GridCombobox.prototype.setActiveItem = function (evt) {
switch (key) {
case aria.KeyCode.UP:
this.gridFocused = true;
if (activeRowIndex <= 0) {
activeRowIndex = this.rowsCount - 1;
}
else {
activeRowIndex--;
}
activeRowIndex = this.getRowIndex(key);
evt.preventDefault();
break;
case aria.KeyCode.DOWN:
this.gridFocused = true;
if (activeRowIndex === -1 || activeRowIndex >= this.rowsCount - 1) {
activeRowIndex = 0;
}
else {
activeRowIndex++;
}
activeRowIndex = this.getRowIndex(key);
evt.preventDefault();
break;
case aria.KeyCode.LEFT:
if (activeColIndex <= 0) {
activeColIndex = this.colsCount - 1;
activeRowIndex = this.getRowIndex(key);
}
else {
activeColIndex--;
Expand All @@ -174,6 +191,7 @@ aria.GridCombobox.prototype.setActiveItem = function (evt) {
case aria.KeyCode.RIGHT:
if (activeColIndex === -1 || activeColIndex >= this.colsCount - 1) {
activeColIndex = 0;
activeRowIndex = this.getRowIndex(key);
}
else {
activeColIndex++;
Expand Down

0 comments on commit 691269e

Please sign in to comment.