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

Commit 353d55a

Browse files
vadim-pdeeg
authored andcommitted
feat(tab): allow active index string
Allow Tab index to be a string Closes #5687 Closes #5577 Closes #5713
1 parent c83d0a8 commit 353d55a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ AngularJS version of the tabs directive.
55
* `active`
66
<i class="glyphicon glyphicon-eye-open"></i>
77
_(Default: `Index of first tab`)_ -
8-
Active index of tab. Setting this to an existing tab index will make that tab active.
8+
Active index of tab. Setting this to an existing tab index will make that tab active. Can be a number or string.
99

1010
* `justified`
1111
<small class="badge">$</small>

Diff for: src/tabs/tabs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ angular.module('ui.bootstrap.tabs', [])
7373
};
7474

7575
$scope.$watch('tabset.active', function(val) {
76-
if (angular.isNumber(val) && val !== oldIndex) {
76+
if ((angular.isNumber(val) || angular.isString(val)) && val !== oldIndex) {
7777
ctrl.select(findTabIndex(val));
7878
}
7979
});
@@ -85,7 +85,7 @@ angular.module('ui.bootstrap.tabs', [])
8585

8686
function findTabIndex(index) {
8787
for (var i = 0; i < ctrl.tabs.length; i++) {
88-
if (ctrl.tabs[i].index === index) {
88+
if (ctrl.tabs[i].index === +index) {
8989
return i;
9090
}
9191
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ describe('tabs', function() {
168168
expect(titles().length).toBe(scope.tabs.length);
169169
expectTabActive(scope.tabs[2]);
170170
});
171+
172+
it("should watch active state", function() {
173+
var controller = elm.controller('uibTabset');
174+
spyOn(controller, "select");
175+
expect(titles().length).toBe(scope.tabs.length);
176+
expectTabActive(scope.tabs[2]);
177+
scope.active = "7";
178+
scope.$apply();
179+
expect(controller.select).toHaveBeenCalledWith(3);
180+
});
171181
});
172182

173183
describe('without active binding and index attributes', function() {

0 commit comments

Comments
 (0)