Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});