Skip to content

Commit 7238f45

Browse files
committed
Merge pull request #3544 from willcodeforbeer/issue3528
Fix for issue 3528. When exiting the grid the focusedCells list was n…
2 parents 91077e8 + af11175 commit 7238f45

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/features/cellnav/js/cellnav.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@
677677
// Figure out which new row+combo we're navigating to
678678
var rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(direction, lastRowCol.row, lastRowCol.col);
679679
var focusableCols = uiGridCtrl.grid.renderContainers[containerId].cellNav.getFocusableCols();
680-
680+
var rowColSelectIndex = uiGridCtrl.grid.api.cellNav.rowColSelectIndex(rowCol);
681681
// Shift+tab on top-left cell should exit cellnav on render container
682682
if (
683683
// Navigating left
@@ -689,6 +689,7 @@
689689
evt.keyCode === uiGridConstants.keymap.TAB &&
690690
evt.shiftKey
691691
) {
692+
grid.cellNav.focusedCells.splice(rowColSelectIndex, 1);
692693
uiGridCtrl.cellNav.clearFocus();
693694
return true;
694695
}
@@ -702,6 +703,7 @@
702703
evt.keyCode === uiGridConstants.keymap.TAB &&
703704
!evt.shiftKey
704705
) {
706+
grid.cellNav.focusedCells.splice(rowColSelectIndex, 1);
705707
uiGridCtrl.cellNav.clearFocus();
706708
return true;
707709
}

src/features/cellnav/test/uiGridCellNavDirective.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,22 @@ describe('ui.grid.cellNav directive', function () {
5353
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[1], col: $scope.grid.columns[0] }, true);
5454
expect($scope.gridApi.cellNav.getCurrentSelection().length).toEqual(2);
5555
});
56+
57+
58+
it('handleKeyDown should clear the focused cells list when clearing focus', function () {
59+
// first ensure that a cell is selected
60+
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true);
61+
var rowColToTest = { row: $scope.grid.rows[0], col: $scope.grid.columns[0] };
62+
var evt = jQuery.Event("keydown");
63+
evt.keyCode = uiGridConstants.keymap.TAB;
64+
$scope.grid.cellNav.lastRowCol = rowColToTest;
65+
66+
// simulate tabbing out of grid
67+
elm.controller('uiGrid').cellNav.handleKeyDown(evt);
68+
expect($scope.grid.cellNav.focusedCells.length).toEqual(0);
69+
70+
// simulate restoring focus
71+
$scope.grid.cellNav.broadcastCellNav({ row: $scope.grid.rows[0], col: $scope.grid.columns[0] }, true);
72+
expect($scope.grid.cellNav.focusedCells.length).toEqual(1);
73+
});
5674
});

0 commit comments

Comments
 (0)