From 353d55af04021259922ecfc52f5220defd93ac9b Mon Sep 17 00:00:00 2001 From: vadim-p Date: Thu, 3 Mar 2016 17:26:41 +0200 Subject: [PATCH] feat(tab): allow active index string Allow Tab index to be a string Closes #5687 Closes #5577 Closes #5713 --- src/tabs/docs/readme.md | 2 +- src/tabs/tabs.js | 4 ++-- src/tabs/test/tabs.spec.js | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/tabs/docs/readme.md b/src/tabs/docs/readme.md index 0bdbfeb9ed..e7239a971c 100644 --- a/src/tabs/docs/readme.md +++ b/src/tabs/docs/readme.md @@ -5,7 +5,7 @@ AngularJS version of the tabs directive. * `active` _(Default: `Index of first tab`)_ - - Active index of tab. Setting this to an existing tab index will make that tab active. + Active index of tab. Setting this to an existing tab index will make that tab active. Can be a number or string. * `justified` $ diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js index adf3c5c7a6..58000a1a68 100644 --- a/src/tabs/tabs.js +++ b/src/tabs/tabs.js @@ -73,7 +73,7 @@ angular.module('ui.bootstrap.tabs', []) }; $scope.$watch('tabset.active', function(val) { - if (angular.isNumber(val) && val !== oldIndex) { + if ((angular.isNumber(val) || angular.isString(val)) && val !== oldIndex) { ctrl.select(findTabIndex(val)); } }); @@ -85,7 +85,7 @@ angular.module('ui.bootstrap.tabs', []) function findTabIndex(index) { for (var i = 0; i < ctrl.tabs.length; i++) { - if (ctrl.tabs[i].index === index) { + if (ctrl.tabs[i].index === +index) { return i; } } diff --git a/src/tabs/test/tabs.spec.js b/src/tabs/test/tabs.spec.js index f2e7642e11..b6774df12b 100644 --- a/src/tabs/test/tabs.spec.js +++ b/src/tabs/test/tabs.spec.js @@ -168,6 +168,16 @@ describe('tabs', function() { expect(titles().length).toBe(scope.tabs.length); expectTabActive(scope.tabs[2]); }); + + it("should watch active state", function() { + var controller = elm.controller('uibTabset'); + spyOn(controller, "select"); + expect(titles().length).toBe(scope.tabs.length); + expectTabActive(scope.tabs[2]); + scope.active = "7"; + scope.$apply(); + expect(controller.select).toHaveBeenCalledWith(3); + }); }); describe('without active binding and index attributes', function() {