Skip to content

Commit

Permalink
feat(core): Accessibility and keyboard support to the filter controls.
Browse files Browse the repository at this point in the history
The filter controls can now be accessed using the tab keys and the
remove filter button automatically moves the focus to the input when it
is disabled.
They also support OSX Voice over reading.
Additionally all of the google accessibility audit rules pass.
The focus input now provides a default aria label on the input that can
be overridden in the filter settings.
  • Loading branch information
JLLeitschuh committed Jul 27, 2015
1 parent ee04132 commit 11a1ae5
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 98 deletions.
14 changes: 11 additions & 3 deletions src/js/core/directives/ui-grid-filter.js
@@ -1,7 +1,7 @@
(function(){
'use strict';

angular.module('ui.grid').directive('uiGridFilter', ['$compile', '$templateCache', function ($compile, $templateCache) {
angular.module('ui.grid').directive('uiGridFilter', ['$compile', '$templateCache', 'i18nService', 'gridUtil', function ($compile, $templateCache, i18nService, gridUtil) {

return {
compile: function() {
Expand All @@ -11,14 +11,22 @@
$elm.children().remove();
if ( filterable ){
var template = $scope.col.filterHeaderTemplate;

$elm.append($compile(template)($scope));
}
};

$scope.$on( '$destroy', function() {
delete $scope.col.updateFilters;
});
},
post: function ($scope, $elm, $attrs, controllers){
$scope.aria = i18nService.getSafeText('headerCell.aria');
$scope.removeFilter = function(colFilter, index){
colFilter.term = null;
//Set the focus to the filter input after the action disables the button
gridUtil.focus.bySelector($elm, '.ui-grid-filter-input-' + index);
};
}
};
}
Expand Down
30 changes: 15 additions & 15 deletions src/js/core/directives/ui-grid-menu.js
Expand Up @@ -16,7 +16,7 @@
var app = angular.module('app', ['ui.grid']);
app.controller('MainCtrl', ['$scope', function ($scope) {
}]);
</script>
Expand All @@ -30,7 +30,7 @@
*/
angular.module('ui.grid')

.directive('uiGridMenu', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants',
.directive('uiGridMenu', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants',
function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
var uiGridMenu = {
priority: 0,
Expand All @@ -46,7 +46,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
var self = this;
var menuMid;
var $animate;

// *** Show/Hide functions ******
self.showMenu = $scope.showMenu = function(event, args) {
if ( !$scope.shown ){
Expand All @@ -57,11 +57,11 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
* animate removal of the ng-if, as the menu items aren't there yet. And we don't want
* to rely on ng-show only, as that leaves elements in the DOM that are needlessly evaluated
* on scroll events.
*
*
* Note when testing animation that animations don't run on the tutorials. When debugging it looks
* like they do, but angular has a default $animate provider that is just a stub, and that's what's
* being called. ALso don't be fooled by the fact that your browser has actually loaded the
* angular-translate.js, it's not using it. You need to test animations in an external application.
* being called. ALso don't be fooled by the fact that your browser has actually loaded the
* angular-translate.js, it's not using it. You need to test animations in an external application.
*/
$scope.shown = true;

Expand Down Expand Up @@ -96,7 +96,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
* In order to animate cleanly we animate the addition of ng-hide, then use a $timeout to
* set the ng-if (shown = false) after the animation runs. In theory we can cascade off the
* callback on the addClass method, but it is very unreliable with unit tests for no discernable reason.
*
*
* The user may have clicked on the menu again whilst
* we're waiting, so we check that the mid isn't shown before applying the ng-if.
*/
Expand All @@ -120,7 +120,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
$scope.showMenu(event, args);
});


// *** Auto hide when click elsewhere ******
var applyHideMenu = function(){
if ($scope.shown) {
Expand All @@ -129,7 +129,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
});
}
};

if (typeof($scope.autoHide) === 'undefined' || $scope.autoHide === undefined) {
$scope.autoHide = true;
}
Expand All @@ -141,7 +141,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
$scope.$on('$destroy', function () {
angular.element(document).off('click touchstart', applyHideMenu);
});


$scope.$on('$destroy', function() {
angular.element($window).off('resize', applyHideMenu);
Expand All @@ -153,8 +153,8 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {

$scope.$on('$destroy', $scope.$on(uiGridConstants.events.ITEM_DRAGGING, applyHideMenu ));
},


controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
var self = this;
}]
Expand Down Expand Up @@ -184,12 +184,12 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
pre: function ($scope, $elm, $attrs, controllers) {
var uiGridCtrl = controllers[0],
uiGridMenuCtrl = controllers[1];

if ($scope.templateUrl) {
gridUtil.getTemplate($scope.templateUrl)
.then(function (contents) {
var template = angular.element(contents);

var newElm = $compile(template)($scope);
$elm.replaceWith(newElm);
});
Expand Down Expand Up @@ -253,4 +253,4 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
return uiGridMenuItem;
}]);

})();
})();

0 comments on commit 11a1ae5

Please sign in to comment.