Skip to content

Commit

Permalink
Grid Examples: Before Moving Focus, Identify Focused Element
Browse files Browse the repository at this point in the history
Focus may move inside the grid as a result of a mouse click or screen reader call to an accessibility API. This change adds a check for the location of focus before processing navigation key events.
  • Loading branch information
tatermelon authored and mcking65 committed Mar 10, 2017
1 parent a00c079 commit 067d52f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/grid/js/dataGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ aria.Grid.prototype.checkFocusChange = function (event) {
return;
}

this.findFocusedItem(event.target);

var key = event.which || event.keyCode;
var rowCaret = this.focusedRow;
var colCaret = this.focusedCol;
Expand Down Expand Up @@ -313,6 +315,32 @@ aria.Grid.prototype.checkFocusChange = function (event) {
event.preventDefault();
};

/**
* @desc
* Reset focused row and col if it doesn't match focusedRow and focusedCol
*
* @param focusedTarget
* Element that is currently focused by browser
*/
aria.Grid.prototype.findFocusedItem = function (focusedTarget) {
var focusedCell = this.grid[this.focusedRow][this.focusedCol];

if (focusedCell === focusedTarget
|| focusedCell.contains(focusedTarget)) {
return;
}

for (var i = 0; i < this.grid.length; i++) {
for (var j = 0; j < this.grid[i].length; j++) {
if (this.grid[i][j] === focusedTarget
|| this.grid[i][j].contains(focusedTarget)) {
this.setFocusPointer(i, j);
return;
}
}
}
};

/**
* @desc
* Triggered on click. Finds the cell that was clicked on and focuses on it.
Expand Down

0 comments on commit 067d52f

Please sign in to comment.