Skip to content

Fix cell focus in cellNav when a new row is added #4740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 18, 2016
Merged
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
25 changes: 21 additions & 4 deletions src/features/cellnav/js/cellnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,10 @@
});
}

// In case we created a new row, and we are the new created row by ngRepeat
// then this cell content might have been selected previously
refreshCellFocus();

function preventMouseDown(evt) {
//Prevents the foucus event from firing if the click event is already going to fire.
//If both events fire it will cause bouncing behavior.
Expand All @@ -1081,16 +1085,27 @@
});

// This event is fired for all cells. If the cell matches, then focus is set
$scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, function (evt, rowCol, modifierDown) {
var isFocused = grid.cellNav.focusedCells.some(function(focusedRowCol, index){
$scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, refreshCellFocus);

// Refresh cell focus when a new row id added to the grid
var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(function (grid) {
// Clear the focus if it's set to avoid the wrong cell getting focused during
// a short period of time (from now until $timeout function executed)
clearFocus();

$timeout(refreshCellFocus);
}, [uiGridConstants.dataChange.ROW]);

function refreshCellFocus() {
var isFocused = grid.cellNav.focusedCells.some(function (focusedRowCol, index) {
return (focusedRowCol.row === $scope.row && focusedRowCol.col === $scope.col);
});
if (isFocused){
if (isFocused) {
setFocused();
} else {
clearFocus();
}
});
}

function setFocused() {
if (!$scope.focused){
Expand All @@ -1113,6 +1128,8 @@
}

$scope.$on('$destroy', function () {
dataChangeDereg();

//.off withouth paramaters removes all handlers
$elm.find('div').off();
$elm.off();
Expand Down