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

Commit 1a870a3

Browse files
committed
feat(pagination): disable tabbing when disabled
- Add directive for toggling `tabindex="-1"` when ngDisabled is true, and removing tabindex when false Closes #5984
1 parent 6038403 commit 1a870a3

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

src/pagination/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require('../paging');
2+
require('../tabindex');
23
require('../../template/pagination/pagination.html.js');
34
require('./pagination');
45

src/pagination/pagination.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module('ui.bootstrap.pagination', ['ui.bootstrap.paging'])
1+
angular.module('ui.bootstrap.pagination', ['ui.bootstrap.paging', 'ui.bootstrap.tabindex'])
22
.controller('UibPaginationController', ['$scope', '$attrs', '$parse', 'uibPaging', 'uibPaginationConfig', function($scope, $attrs, $parse, uibPaging, uibPaginationConfig) {
33
var ctrl = this;
44
// Setup configuration parameters

src/tabindex/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require('./tabindex');
2+
3+
var MODULE_NAME = 'ui.bootstrap.module.tabindex';
4+
5+
angular.module(MODULE_NAME, ['ui.bootstrap.tabindex']);
6+
7+
module.exports = MODULE_NAME;

src/tabindex/tabindex.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
angular.module('ui.bootstrap.tabindex', [])
2+
3+
.directive('uibTabindexToggle', function() {
4+
return {
5+
restrict: 'A',
6+
link: function(scope, elem, attrs) {
7+
attrs.$observe('disabled', function(disabled) {
8+
attrs.$set('tabindex', disabled ? -1 : null);
9+
});
10+
}
11+
};
12+
});

src/tabindex/test/tabindex.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
describe('tabindex toggle directive', function() {
2+
var $rootScope, element;
3+
beforeEach(module('ui.bootstrap.tabindex'));
4+
beforeEach(inject(function($compile, _$rootScope_) {
5+
$rootScope = _$rootScope_;
6+
element = $compile('<a href uib-tabindex-toggle ng-disabled="disabled">foo</a>')($rootScope);
7+
$rootScope.$digest();
8+
}));
9+
10+
it('should toggle the tabindex on disabled toggle', function() {
11+
expect(element.prop('tabindex')).toBe(0);
12+
13+
$rootScope.disabled = true;
14+
$rootScope.$digest();
15+
16+
expect(element.prop('tabindex')).toBe(-1);
17+
18+
$rootScope.disabled = false;
19+
$rootScope.$digest();
20+
21+
expect(element.prop('tabindex')).toBe(0);
22+
});
23+
});

template/pagination/pagination.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ul class="pagination">
2-
<li ng-if="::boundaryLinks" ng-class="{disabled: noPrevious()||ngDisabled}" class="pagination-first"><a href ng-click="selectPage(1, $event)">{{::getText('first')}}</a></li>
3-
<li ng-if="::directionLinks" ng-class="{disabled: noPrevious()||ngDisabled}" class="pagination-prev"><a href ng-click="selectPage(page - 1, $event)">{{::getText('previous')}}</a></li>
4-
<li ng-repeat="page in pages track by $index" ng-class="{active: page.active,disabled: ngDisabled&&!page.active}" class="pagination-page"><a href ng-click="selectPage(page.number, $event)">{{page.text}}</a></li>
5-
<li ng-if="::directionLinks" ng-class="{disabled: noNext()||ngDisabled}" class="pagination-next"><a href ng-click="selectPage(page + 1, $event)">{{::getText('next')}}</a></li>
6-
<li ng-if="::boundaryLinks" ng-class="{disabled: noNext()||ngDisabled}" class="pagination-last"><a href ng-click="selectPage(totalPages, $event)">{{::getText('last')}}</a></li>
2+
<li ng-if="::boundaryLinks" ng-class="{disabled: noPrevious()||ngDisabled}" class="pagination-first"><a href ng-click="selectPage(1, $event)" ng-disabled="noPrevious()||ngDisabled" uib-tabindex-toggle>{{::getText('first')}}</a></li>
3+
<li ng-if="::directionLinks" ng-class="{disabled: noPrevious()||ngDisabled}" class="pagination-prev"><a href ng-click="selectPage(page - 1, $event)" ng-disabled="noPrevious()||ngDisabled" uib-tabindex-toggle>{{::getText('previous')}}</a></li>
4+
<li ng-repeat="page in pages track by $index" ng-class="{active: page.active,disabled: ngDisabled&&!page.active}" class="pagination-page"><a href ng-click="selectPage(page.number, $event)" ng-disabled="ngDisabled&&!page.active" uib-tabindex-toggle>{{page.text}}</a></li>
5+
<li ng-if="::directionLinks" ng-class="{disabled: noNext()||ngDisabled}" class="pagination-next"><a href ng-click="selectPage(page + 1, $event)" ng-disabled="noNext()||ngDisabled" uib-tabindex-toggle>{{::getText('next')}}</a></li>
6+
<li ng-if="::boundaryLinks" ng-class="{disabled: noNext()||ngDisabled}" class="pagination-last"><a href ng-click="selectPage(totalPages, $event)" ng-disabled="noNext()||ngDisabled" uib-tabindex-toggle>{{::getText('last')}}</a></li>
77
</ul>

0 commit comments

Comments
 (0)