Skip to content

Commit

Permalink
feat(tab): allow active index string
Browse files Browse the repository at this point in the history
Allow Tab index to be a string

Closes angular-ui#5687
Closes angular-ui#5577
  • Loading branch information
vadim-p authored and deeg committed Mar 31, 2016
1 parent c83d0a8 commit 19723b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/tabs/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ AngularJS version of the tabs directive.
* `active`
<i class="glyphicon glyphicon-eye-open"></i>
_(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`
<small class="badge">$</small>
Expand Down
4 changes: 2 additions & 2 deletions src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});
Expand All @@ -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;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/tabs/test/tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 19723b2

Please sign in to comment.