Skip to content

Commit

Permalink
Fix for issue 3528. When exiting the grid the focusedCells list was n…
Browse files Browse the repository at this point in the history
…ot getting cleared which meant that if focus was returned the book keeping around cell focus was not done.
  • Loading branch information
Kyle Wuolle committed May 20, 2015
1 parent c0d9b48 commit af11175
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/features/cellnav/js/cellnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@
// Figure out which new row+combo we're navigating to
var rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(direction, lastRowCol.row, lastRowCol.col);
var focusableCols = uiGridCtrl.grid.renderContainers[containerId].cellNav.getFocusableCols();

var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol);
// Shift+tab on top-left cell should exit cellnav on render container
if (
// Navigating left
Expand All @@ -689,6 +689,7 @@
evt.keyCode === uiGridConstants.keymap.TAB &&
evt.shiftKey
) {
grid.cellNav.focusedCells.splice(rowColSelectIndex, 1);
uiGridCtrl.cellNav.clearFocus();
return true;
}
Expand All @@ -702,6 +703,7 @@
evt.keyCode === uiGridConstants.keymap.TAB &&
!evt.shiftKey
) {
grid.cellNav.focusedCells.splice(rowColSelectIndex, 1);
uiGridCtrl.cellNav.clearFocus();
return true;
}
Expand Down
18 changes: 18 additions & 0 deletions src/features/cellnav/test/uiGridCellNavDirective.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,22 @@ describe('ui.grid.cellNav directive', function () {
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[1], col: $scope.grid.columns[0] }, true);
expect($scope.gridApi.cellNav.getCurrentSelection().length).toEqual(2);
});


it('handleKeyDown should clear the focused cells list when clearing focus', function () {
// first ensure that a cell is selected
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true);
var rowColToTest = { row: $scope.grid.rows[0], col: $scope.grid.columns[0] };
var evt = jQuery.Event("keydown");
evt.keyCode = uiGridConstants.keymap.TAB;
$scope.grid.cellNav.lastRowCol = rowColToTest;

// simulate tabbing out of grid
elm.controller('uiGrid').cellNav.handleKeyDown(evt);
expect($scope.grid.cellNav.focusedCells.length).toEqual(0);

// simulate restoring focus
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true);
expect($scope.grid.cellNav.focusedCells.length).toEqual(1);
});
});

0 comments on commit af11175

Please sign in to comment.