Skip to content

Commit

Permalink
Accessible keyboard nav (#56)
Browse files Browse the repository at this point in the history
* Allow key down to toggle sort

* fix(ui-grid-util): add out of sync changes

* fix(core): don't use keycode
  • Loading branch information
JeffRiggle authored May 21, 2019
1 parent 237ad33 commit 8eb2544
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions src/js/core/directives/ui-grid-header-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,25 @@

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

$scope.handleClick = function(event) {
// If the shift key is being held down, add this column to the sort
var add = false;
if (event.shiftKey) {
add = true;
}

function applySort(add) {
// Sort this column then rebuild the grid's rows
uiGridCtrl.grid.sortColumn($scope.col, add)
.then(function () {
if (uiGridCtrl.columnMenuScope) { uiGridCtrl.columnMenuScope.hideMenu(); }
uiGridCtrl.grid.refresh();
}).catch(angular.noop);
}

$scope.handleClick = function(event) {
// If the shift key is being held down, add this column to the sort
applySort(event.shiftKey);
};

$scope.handleKeyDown = function(event) {
if (event.key === 'Enter' || event.key === ' ') {
applySort(event.shiftKey);
}
};

$scope.toggleMenu = function(event) {
event.stopPropagation();
Expand Down
6 changes: 3 additions & 3 deletions src/js/core/services/ui-grid-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
return columnName.replace(/_+/g, ' ')
// Replace a completely all-capsed word with a first-letter-capitalized version
.replace(/^[A-Z]+$/, function (match) {
return angular.lowercase(angular.uppercase(match.charAt(0)) + match.slice(1));
return match.toLowerCase();
})
// Capitalize the first letter of words
.replace(/([\w\u00C0-\u017F]+)/g, function (match) {
return angular.uppercase(match.charAt(0)) + match.slice(1);
return match.charAt(0).toUpperCase();
})
// Put a space in between words that have partial capilizations (i.e. 'firstName' becomes 'First Name')
// .replace(/([A-Z]|[A-Z]\w+)([A-Z])/g, "$1 $2");
Expand Down Expand Up @@ -900,7 +900,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC


['width', 'height'].forEach(function (name) {
var capsName = angular.uppercase(name.charAt(0)) + name.substr(1);
var capsName = name.charAt(0).toUpperCase() + name.substr(1);
s['element' + capsName] = function (elem, extra) {
var e = elem;
if (e && typeof(e.length) !== 'undefined' && e.length) {
Expand Down

0 comments on commit 8eb2544

Please sign in to comment.