diff --git a/src/pagination/pagination.js b/src/pagination/pagination.js
index f022dce540..3357baab5d 100644
--- a/src/pagination/pagination.js
+++ b/src/pagination/pagination.js
@@ -32,8 +32,11 @@ angular.module('ui.bootstrap.pagination', [])
$scope.page = parseInt(ngModelCtrl.$viewValue, 10) || 1;
};
- $scope.selectPage = function(page) {
+ $scope.selectPage = function(page, evt) {
if ( $scope.page !== page && page > 0 && page <= $scope.totalPages) {
+ if (evt && evt.target) {
+ evt.target.blur();
+ }
ngModelCtrl.$setViewValue(page);
ngModelCtrl.$render();
}
diff --git a/src/pagination/test/pager.spec.js b/src/pagination/test/pager.spec.js
index 5a6010b2ad..370ef073e0 100644
--- a/src/pagination/test/pager.spec.js
+++ b/src/pagination/test/pager.spec.js
@@ -1,12 +1,13 @@
describe('pager directive', function () {
- var $compile, $rootScope, element;
+ var $compile, $rootScope, $document, element;
beforeEach(module('ui.bootstrap.pagination'));
beforeEach(module('template/pagination/pager.html'));
- beforeEach(inject(function(_$compile_, _$rootScope_) {
+ beforeEach(inject(function(_$compile_, _$rootScope_, _$document_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$rootScope.total = 47; // 5 pages
$rootScope.currentPage = 3;
+ $document = _$document_;
element = $compile('')($rootScope);
$rootScope.$digest();
}));
@@ -22,6 +23,10 @@ describe('pager directive', function () {
function clickPaginationEl(index) {
getPaginationEl(index).find('a').click();
}
+
+ function getPaginationLinkEl(elem, index) {
+ return elem.find('li').eq(index).find('a');
+ }
function updateCurrentPage(value) {
$rootScope.currentPage = value;
@@ -96,6 +101,32 @@ describe('pager directive', function () {
expect(getPaginationEl(-1).text()).toBe('Next ยป');
});
+ it('should blur the "next" link after it has been clicked', function () {
+ $document.find('body').append(element);
+ var linkEl = getPaginationLinkEl(element, -1);
+
+ linkEl.focus();
+ expect(linkEl).toHaveFocus();
+
+ linkEl.click();
+ expect(linkEl).not.toHaveFocus();
+
+ element.remove();
+ });
+
+ it('should blur the "prev" link after it has been clicked', function () {
+ $document.find('body').append(element);
+ var linkEl = getPaginationLinkEl(element, -1);
+
+ linkEl.focus();
+ expect(linkEl).toHaveFocus();
+
+ linkEl.click();
+ expect(linkEl).not.toHaveFocus();
+
+ element.remove();
+ });
+
describe('`items-per-page`', function () {
beforeEach(function() {
$rootScope.perpage = 5;
diff --git a/src/pagination/test/pagination.spec.js b/src/pagination/test/pagination.spec.js
index 70ace520a5..19a9618c28 100644
--- a/src/pagination/test/pagination.spec.js
+++ b/src/pagination/test/pagination.spec.js
@@ -1,12 +1,13 @@
describe('pagination directive', function () {
- var $compile, $rootScope, element;
+ var $compile, $rootScope, $document, element;
beforeEach(module('ui.bootstrap.pagination'));
beforeEach(module('template/pagination/pagination.html'));
- beforeEach(inject(function(_$compile_, _$rootScope_) {
+ beforeEach(inject(function(_$compile_, _$rootScope_, _$document_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$rootScope.total = 47; // 5 pages
$rootScope.currentPage = 3;
+ $document = _$document_;
element = $compile('')($rootScope);
$rootScope.$digest();
}));
@@ -22,6 +23,10 @@ describe('pagination directive', function () {
function clickPaginationEl(index) {
getPaginationEl(index).find('a').click();
}
+
+ function getPaginationLinkEl(elem, index) {
+ return elem.find('li').eq(index).find('a');
+ }
function updateCurrentPage(value) {
$rootScope.currentPage = value;
@@ -122,6 +127,45 @@ describe('pagination directive', function () {
expect($rootScope.currentPage).toBe(1);
});
+ it('should blur a page link after it has been clicked', function () {
+ $document.find('body').append(element);
+ var linkEl = getPaginationLinkEl(element, 2);
+
+ linkEl.focus();
+ expect(linkEl).toHaveFocus();
+
+ linkEl.click();
+ expect(linkEl).not.toHaveFocus();
+
+ element.remove();
+ });
+
+ it('should blur the "next" link after it has been clicked', function () {
+ $document.find('body').append(element);
+ var linkEl = getPaginationLinkEl(element, -1);
+
+ linkEl.focus();
+ expect(linkEl).toHaveFocus();
+
+ linkEl.click();
+ expect(linkEl).not.toHaveFocus();
+
+ element.remove();
+ });
+
+ it('should blur the "prev" link after it has been clicked', function () {
+ $document.find('body').append(element);
+ var linkEl = getPaginationLinkEl(element, 0);
+
+ linkEl.focus();
+ expect(linkEl).toHaveFocus();
+
+ linkEl.click();
+ expect(linkEl).not.toHaveFocus();
+
+ element.remove();
+ });
+
describe('`items-per-page`', function () {
beforeEach(function() {
$rootScope.perpage = 5;
@@ -259,6 +303,19 @@ describe('pagination directive', function () {
expect(getPaginationEl(0).text()).toBe('Previous');
expect(getPaginationEl(-1).text()).toBe('Next');
});
+
+ it('should blur page link when visible range changes', function () {
+ $document.find('body').append(element);
+ var linkEl = getPaginationLinkEl(element, 4);
+
+ linkEl.focus();
+ expect(linkEl).toHaveFocus();
+
+ linkEl.click();
+ expect(linkEl).not.toHaveFocus();
+
+ element.remove();
+ });
});
describe('with `max-size` option & no `rotate`', function () {
@@ -415,6 +472,32 @@ describe('pagination directive', function () {
expect(getPaginationEl(1).text()).toBe('<<');
expect(getPaginationEl(-2).text()).toBe('>>');
});
+
+ it('should blur the "first" link after it has been clicked', function () {
+ $document.find('body').append(element);
+ var linkEl = getPaginationLinkEl(element, 0);
+
+ linkEl.focus();
+ expect(linkEl).toHaveFocus();
+
+ linkEl.click();
+ expect(linkEl).not.toHaveFocus();
+
+ element.remove();
+ });
+
+ it('should blur the "last" link after it has been clicked', function () {
+ $document.find('body').append(element);
+ var linkEl = getPaginationLinkEl(element, -1);
+
+ linkEl.focus();
+ expect(linkEl).toHaveFocus();
+
+ linkEl.click();
+ expect(linkEl).not.toHaveFocus();
+
+ element.remove();
+ });
});
describe('pagination directive with just number links', function () {
diff --git a/template/pagination/pager.html b/template/pagination/pager.html
index ca150de164..84b143c7e5 100644
--- a/template/pagination/pager.html
+++ b/template/pagination/pager.html
@@ -1,4 +1,4 @@
\ No newline at end of file
diff --git a/template/pagination/pagination.html b/template/pagination/pagination.html
index cd45d290d5..acd101a995 100644
--- a/template/pagination/pagination.html
+++ b/template/pagination/pagination.html
@@ -1,7 +1,7 @@
\ No newline at end of file