diff --git a/src/pagination/index.js b/src/pagination/index.js index 0262f24388..07899c79b0 100644 --- a/src/pagination/index.js +++ b/src/pagination/index.js @@ -1,4 +1,5 @@ require('../paging'); +require('../tabindex'); require('../../template/pagination/pagination.html.js'); require('./pagination'); diff --git a/src/pagination/pagination.js b/src/pagination/pagination.js index 6706795c84..c9633f4d60 100644 --- a/src/pagination/pagination.js +++ b/src/pagination/pagination.js @@ -1,4 +1,4 @@ -angular.module('ui.bootstrap.pagination', ['ui.bootstrap.paging']) +angular.module('ui.bootstrap.pagination', ['ui.bootstrap.paging', 'ui.bootstrap.tabindex']) .controller('UibPaginationController', ['$scope', '$attrs', '$parse', 'uibPaging', 'uibPaginationConfig', function($scope, $attrs, $parse, uibPaging, uibPaginationConfig) { var ctrl = this; // Setup configuration parameters diff --git a/src/tabindex/index.js b/src/tabindex/index.js new file mode 100644 index 0000000000..5d6b5663dc --- /dev/null +++ b/src/tabindex/index.js @@ -0,0 +1,7 @@ +require('./tabindex'); + +var MODULE_NAME = 'ui.bootstrap.module.tabindex'; + +angular.module(MODULE_NAME, ['ui.bootstrap.tabindex']); + +module.exports = MODULE_NAME; diff --git a/src/tabindex/tabindex.js b/src/tabindex/tabindex.js new file mode 100644 index 0000000000..a00a0aff3b --- /dev/null +++ b/src/tabindex/tabindex.js @@ -0,0 +1,12 @@ +angular.module('ui.bootstrap.tabindex', []) + +.directive('uibTabindexToggle', function() { + return { + restrict: 'A', + link: function(scope, elem, attrs) { + attrs.$observe('disabled', function(disabled) { + attrs.$set('tabindex', disabled ? -1 : null); + }); + } + }; +}); diff --git a/src/tabindex/test/tabindex.spec.js b/src/tabindex/test/tabindex.spec.js new file mode 100644 index 0000000000..b1a2159d82 --- /dev/null +++ b/src/tabindex/test/tabindex.spec.js @@ -0,0 +1,23 @@ +describe('tabindex toggle directive', function() { + var $rootScope, element; + beforeEach(module('ui.bootstrap.tabindex')); + beforeEach(inject(function($compile, _$rootScope_) { + $rootScope = _$rootScope_; + element = $compile('foo')($rootScope); + $rootScope.$digest(); + })); + + it('should toggle the tabindex on disabled toggle', function() { + expect(element.prop('tabindex')).toBe(0); + + $rootScope.disabled = true; + $rootScope.$digest(); + + expect(element.prop('tabindex')).toBe(-1); + + $rootScope.disabled = false; + $rootScope.$digest(); + + expect(element.prop('tabindex')).toBe(0); + }); +}); diff --git a/template/pagination/pagination.html b/template/pagination/pagination.html index f55a7b6b92..1fa607b54b 100644 --- a/template/pagination/pagination.html +++ b/template/pagination/pagination.html @@ -1,7 +1,7 @@