Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit e0e5d71

Browse files
committed
feat(timepicker): add accessibility improvements
- Add ng-disabled usage in template - Add `timepickerTabindex` attribute support for binding tabindex to timepicker controls
1 parent 9e71da8 commit e0e5d71

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

Diff for: src/timepicker/docs/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ All settings can be provided as attributes in the `<uib-timepicker>` or globally
5050
* `max`
5151
_(Defaults: undefined)_ :
5252
Maximum time a user can select
53+
54+
* `tabindex`
55+
_(Defaults: 0)_ :
56+
Sets tabindex for each control in timepicker

Diff for: src/timepicker/test/timepicker.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,21 @@ describe('timepicker directive', function() {
937937
expect(getModelState()).toEqual([16, 40]);
938938
expect(element.hasClass('ng-invalid-time')).toBe(false);
939939
});
940+
941+
it('should have a default tabindex of 0', function() {
942+
element = $compile('<uib-timepicker ng-model="time"></uib-timepicker>')($rootScope);
943+
$rootScope.$digest();
944+
945+
expect(element.isolateScope().tabindex).toBe(0);
946+
});
947+
948+
it('should have the correct tabindex', function() {
949+
element = $compile('<uib-timepicker ng-model="time" tabindex="5"></uib-timepicker>')($rootScope);
950+
$rootScope.$digest();
951+
952+
expect(element.attr('tabindex')).toBe(undefined);
953+
expect(element.isolateScope().tabindex).toBe('5');
954+
});
940955
});
941956

942957
describe('when model is not a Date', function() {

Diff for: src/timepicker/timepicker.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ angular.module('ui.bootstrap.timepicker', [])
1111
showSpinners: true
1212
})
1313

14-
.controller('UibTimepickerController', ['$scope', '$attrs', '$parse', '$log', '$locale', 'uibTimepickerConfig', function($scope, $attrs, $parse, $log, $locale, timepickerConfig) {
14+
.controller('UibTimepickerController', ['$scope', '$element', '$attrs', '$parse', '$log', '$locale', 'uibTimepickerConfig', function($scope, $element, $attrs, $parse, $log, $locale, timepickerConfig) {
1515
var selected = new Date(),
1616
ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl
1717
meridians = angular.isDefined($attrs.meridians) ? $scope.$parent.$eval($attrs.meridians) : timepickerConfig.meridians || $locale.DATETIME_FORMATS.AMPMS;
1818

19+
$scope.tabindex = angular.isDefined($attrs.tabindex) ? $attrs.tabindex : 0;
20+
$element.removeAttr('tabindex');
21+
1922
this.init = function(ngModelCtrl_, inputs) {
2023
ngModelCtrl = ngModelCtrl_;
2124
ngModelCtrl.$render = this.render;
@@ -386,13 +389,14 @@ angular.module('ui.bootstrap.timepicker')
386389

387390
.value('$timepickerSuppressWarning', false)
388391

389-
.controller('TimepickerController', ['$scope', '$attrs', '$controller', '$log', '$timepickerSuppressWarning', function($scope, $attrs, $controller, $log, $timepickerSuppressWarning) {
392+
.controller('TimepickerController', ['$scope', '$element', '$attrs', '$controller', '$log', '$timepickerSuppressWarning', function($scope, $element, $attrs, $controller, $log, $timepickerSuppressWarning) {
390393
if (!$timepickerSuppressWarning) {
391394
$log.warn('TimepickerController is now deprecated. Use UibTimepickerController instead.');
392395
}
393396

394397
return $controller('UibTimepickerController', {
395398
$scope: $scope,
399+
$element: $element,
396400
$attrs: $attrs
397401
});
398402
}])

Diff for: template/timepicker/timepicker.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<table>
22
<tbody>
33
<tr class="text-center" ng-show="::showSpinners">
4-
<td><a ng-click="incrementHours()" ng-class="{disabled: noIncrementHours()}" class="btn btn-link"><span class="glyphicon glyphicon-chevron-up"></span></a></td>
4+
<td><a ng-click="incrementHours()" ng-class="{disabled: noIncrementHours()}" class="btn btn-link" ng-disabled="noIncrementHours()" tabindex="{{::tabindex}}"><span class="glyphicon glyphicon-chevron-up"></span></a></td>
55
<td>&nbsp;</td>
6-
<td><a ng-click="incrementMinutes()" ng-class="{disabled: noIncrementMinutes()}" class="btn btn-link"><span class="glyphicon glyphicon-chevron-up"></span></a></td>
6+
<td><a ng-click="incrementMinutes()" ng-class="{disabled: noIncrementMinutes()}" class="btn btn-link" ng-disabled="noIncrementMinutes()" tabindex="{{::tabindex}}"><span class="glyphicon glyphicon-chevron-up"></span></a></td>
77
<td ng-show="showMeridian"></td>
88
</tr>
99
<tr>
1010
<td class="form-group" ng-class="{'has-error': invalidHours}">
11-
<input style="width:50px;" type="text" ng-model="hours" ng-change="updateHours()" class="form-control text-center" ng-readonly="::readonlyInput" maxlength="2">
11+
<input style="width:50px;" type="text" ng-model="hours" ng-change="updateHours()" class="form-control text-center" ng-readonly="::readonlyInput" maxlength="2" tabindex="{{::tabindex}}">
1212
</td>
1313
<td>:</td>
1414
<td class="form-group" ng-class="{'has-error': invalidMinutes}">
15-
<input style="width:50px;" type="text" ng-model="minutes" ng-change="updateMinutes()" class="form-control text-center" ng-readonly="::readonlyInput" maxlength="2">
15+
<input style="width:50px;" type="text" ng-model="minutes" ng-change="updateMinutes()" class="form-control text-center" ng-readonly="::readonlyInput" maxlength="2" tabindex="{{::tabindex}}">
1616
</td>
17-
<td ng-show="showMeridian"><button type="button" ng-class="{disabled: noToggleMeridian()}" class="btn btn-default text-center" ng-click="toggleMeridian()">{{meridian}}</button></td>
17+
<td ng-show="showMeridian"><button type="button" ng-class="{disabled: noToggleMeridian()}" class="btn btn-default text-center" ng-click="toggleMeridian()" ng-disabled="noToggleMeridian()" tabindex="{{::tabindex}}">{{meridian}}</button></td>
1818
</tr>
1919
<tr class="text-center" ng-show="::showSpinners">
20-
<td><a ng-click="decrementHours()" ng-class="{disabled: noDecrementHours()}" class="btn btn-link"><span class="glyphicon glyphicon-chevron-down"></span></a></td>
20+
<td><a ng-click="decrementHours()" ng-class="{disabled: noDecrementHours()}" class="btn btn-link" ng-disabled="noDecrementHours()" tabindex="{{::tabindex}}"><span class="glyphicon glyphicon-chevron-down"></span></a></td>
2121
<td>&nbsp;</td>
22-
<td><a ng-click="decrementMinutes()" ng-class="{disabled: noDecrementMinutes()}" class="btn btn-link"><span class="glyphicon glyphicon-chevron-down"></span></a></td>
22+
<td><a ng-click="decrementMinutes()" ng-class="{disabled: noDecrementMinutes()}" class="btn btn-link" ng-disabled="noDecrementMinutes()" tabindex="{{::tabindex}}"><span class="glyphicon glyphicon-chevron-down"></span></a></td>
2323
<td ng-show="showMeridian"></td>
2424
</tr>
2525
</tbody>

0 commit comments

Comments
 (0)