Skip to content

Commit

Permalink
Merge pull request angular-ui#1531 from panuhorsmalahti/2.x
Browse files Browse the repository at this point in the history
Add noKeyboardNavigation option.
  • Loading branch information
c0bra committed Oct 6, 2014
2 parents 313edd2 + 598231a commit e32a214
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/navigation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//set event binding on the grid so we can select using the up/down keys
var ngMoveSelectionHandler = function($scope, elm, evt, grid) {
if ($scope.selectionProvider.selectedItems === undefined) {
if ($scope.selectionProvider.selectedItems === undefined || grid.config.noKeyboardNavigation) {
return true;
}

Expand All @@ -25,7 +25,7 @@ var ngMoveSelectionHandler = function($scope, elm, evt, grid) {
if (charCode !== 37 && charCode !== 38 && charCode !== 39 && charCode !== 40 && (grid.config.noTabInterference || charCode !== 9) && charCode !== 13) {
return true;
}

if ($scope.enableCellSelection) {
if (charCode === 9) { //tab key
evt.preventDefault();
Expand All @@ -36,7 +36,7 @@ var ngMoveSelectionHandler = function($scope, elm, evt, grid) {
var focusedOnLastVisibleColumns = newColumnIndex === (visibleCols.length - 1) || newColumnIndex === (visibleCols.length - 2);
var focusedOnLastColumn = visibleCols.indexOf($scope.col) === (visibleCols.length - 1);
var focusedOnLastPinnedColumn = pinnedCols.indexOf($scope.col) === (pinnedCols.length - 1);

if (charCode === 37 || charCode === 9 && evt.shiftKey) {
var scrollTo = 0;

Expand All @@ -59,13 +59,13 @@ var ngMoveSelectionHandler = function($scope, elm, evt, grid) {
}

grid.$viewport.scrollLeft(scrollTo);

}
else if (charCode === 39 || charCode === 9 && !evt.shiftKey) {
if (focusedOnLastVisibleColumns) {
if (focusedOnLastColumn && charCode === 9 && !evt.shiftKey) {
grid.$viewport.scrollLeft(0);
newColumnIndex = $scope.showSelectionCheckbox ? 1 : 0;
newColumnIndex = $scope.showSelectionCheckbox ? 1 : 0;
lastInRow = true;
}
else {
Expand All @@ -81,7 +81,7 @@ var ngMoveSelectionHandler = function($scope, elm, evt, grid) {
}
}
}

var items;
if ($scope.configGroups.length > 0) {
items = grid.rowFactory.parsedData.filter(function (row) {
Expand All @@ -91,15 +91,15 @@ var ngMoveSelectionHandler = function($scope, elm, evt, grid) {
else {
items = grid.filteredRows;
}

var offset = 0;
if (rowIndex !== 0 && (charCode === 38 || charCode === 13 && evt.shiftKey || charCode === 9 && evt.shiftKey && firstInRow)) { //arrow key up or shift enter or tab key and first item in row
offset = -1;
}
else if (rowIndex !== items.length - 1 && (charCode === 40 || charCode === 13 && !evt.shiftKey || charCode === 9 && lastInRow)) {//arrow key down, enter, or tab key and last item in row?
offset = 1;
}

if (offset) {
var r = items[rowIndex + offset];
if (r.beforeSelectionChange(r, evt)) {
Expand All @@ -114,7 +114,7 @@ var ngMoveSelectionHandler = function($scope, elm, evt, grid) {
}
}
}

if ($scope.enableCellSelection) {
setTimeout(function(){
$scope.domAccessProvider.focusCellElement($scope, $scope.renderedColumns.indexOf(visibleCols[newColumnIndex]));
Expand Down

0 comments on commit e32a214

Please sign in to comment.