Skip to content

Commit 11a1ae5

Browse files
committed
feat(core): Accessibility and keyboard support to the filter controls.
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.
1 parent ee04132 commit 11a1ae5

File tree

5 files changed

+147
-98
lines changed

5 files changed

+147
-98
lines changed

src/js/core/directives/ui-grid-filter.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function(){
22
'use strict';
33

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

66
return {
77
compile: function() {
@@ -11,14 +11,22 @@
1111
$elm.children().remove();
1212
if ( filterable ){
1313
var template = $scope.col.filterHeaderTemplate;
14-
14+
1515
$elm.append($compile(template)($scope));
1616
}
1717
};
18-
18+
1919
$scope.$on( '$destroy', function() {
2020
delete $scope.col.updateFilters;
2121
});
22+
},
23+
post: function ($scope, $elm, $attrs, controllers){
24+
$scope.aria = i18nService.getSafeText('headerCell.aria');
25+
$scope.removeFilter = function(colFilter, index){
26+
colFilter.term = null;
27+
//Set the focus to the filter input after the action disables the button
28+
gridUtil.focus.bySelector($elm, '.ui-grid-filter-input-' + index);
29+
};
2230
}
2331
};
2432
}

src/js/core/directives/ui-grid-menu.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
var app = angular.module('app', ['ui.grid']);
1717
1818
app.controller('MainCtrl', ['$scope', function ($scope) {
19-
19+
2020
}]);
2121
</script>
2222
@@ -30,7 +30,7 @@
3030
*/
3131
angular.module('ui.grid')
3232

33-
.directive('uiGridMenu', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants',
33+
.directive('uiGridMenu', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants',
3434
function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
3535
var uiGridMenu = {
3636
priority: 0,
@@ -46,7 +46,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
4646
var self = this;
4747
var menuMid;
4848
var $animate;
49-
49+
5050
// *** Show/Hide functions ******
5151
self.showMenu = $scope.showMenu = function(event, args) {
5252
if ( !$scope.shown ){
@@ -57,11 +57,11 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
5757
* animate removal of the ng-if, as the menu items aren't there yet. And we don't want
5858
* to rely on ng-show only, as that leaves elements in the DOM that are needlessly evaluated
5959
* on scroll events.
60-
*
60+
*
6161
* Note when testing animation that animations don't run on the tutorials. When debugging it looks
6262
* like they do, but angular has a default $animate provider that is just a stub, and that's what's
63-
* being called. ALso don't be fooled by the fact that your browser has actually loaded the
64-
* angular-translate.js, it's not using it. You need to test animations in an external application.
63+
* being called. ALso don't be fooled by the fact that your browser has actually loaded the
64+
* angular-translate.js, it's not using it. You need to test animations in an external application.
6565
*/
6666
$scope.shown = true;
6767

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

123-
123+
124124
// *** Auto hide when click elsewhere ******
125125
var applyHideMenu = function(){
126126
if ($scope.shown) {
@@ -129,7 +129,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
129129
});
130130
}
131131
};
132-
132+
133133
if (typeof($scope.autoHide) === 'undefined' || $scope.autoHide === undefined) {
134134
$scope.autoHide = true;
135135
}
@@ -141,7 +141,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
141141
$scope.$on('$destroy', function () {
142142
angular.element(document).off('click touchstart', applyHideMenu);
143143
});
144-
144+
145145

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

154154
$scope.$on('$destroy', $scope.$on(uiGridConstants.events.ITEM_DRAGGING, applyHideMenu ));
155155
},
156-
157-
156+
157+
158158
controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
159159
var self = this;
160160
}]
@@ -184,12 +184,12 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
184184
pre: function ($scope, $elm, $attrs, controllers) {
185185
var uiGridCtrl = controllers[0],
186186
uiGridMenuCtrl = controllers[1];
187-
187+
188188
if ($scope.templateUrl) {
189189
gridUtil.getTemplate($scope.templateUrl)
190190
.then(function (contents) {
191191
var template = angular.element(contents);
192-
192+
193193
var newElm = $compile(template)($scope);
194194
$elm.replaceWith(newElm);
195195
});
@@ -253,4 +253,4 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants) {
253253
return uiGridMenuItem;
254254
}]);
255255

256-
})();
256+
})();

0 commit comments

Comments
 (0)