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

Commit

Permalink
feat(tab): allow strings for index
Browse files Browse the repository at this point in the history
- Allows the use of strings for the tab index and active value
on the tabset.

Closes #5713
Closes #5827
  • Loading branch information
RobJacobs committed May 9, 2016
1 parent 9436b9e commit 26d3995
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/tabs/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ AngularJS version of the tabs directive.
Heading text.

* `index` -
Tab index. Must be unique number.
Tab index. Must be unique number or string.

* `select()`
<small class="badge">$</small> -
Expand Down
6 changes: 3 additions & 3 deletions src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ angular.module('ui.bootstrap.tabs', [])
selected.tab.active = true;
ctrl.active = selected.index;
oldIndex = selected.index;
} else if (!selected && angular.isNumber(oldIndex)) {
} else if (!selected && angular.isDefined(oldIndex)) {
ctrl.active = null;
oldIndex = null;
}
Expand All @@ -52,7 +52,7 @@ angular.module('ui.bootstrap.tabs', [])
return 0;
});

if (tab.index === ctrl.active || !angular.isNumber(ctrl.active) && ctrl.tabs.length === 1) {
if (tab.index === ctrl.active || !angular.isDefined(ctrl.active) && ctrl.tabs.length === 1) {
var newActiveIndex = findTabIndex(tab.index);
ctrl.select(newActiveIndex);
}
Expand All @@ -77,7 +77,7 @@ angular.module('ui.bootstrap.tabs', [])
};

$scope.$watch('tabset.active', function(val) {
if (angular.isNumber(val) && val !== oldIndex) {
if (angular.isDefined(val) && val !== oldIndex) {
ctrl.select(findTabIndex(val));
}
});
Expand Down
35 changes: 35 additions & 0 deletions src/tabs/test/tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,41 @@ describe('tabs', function() {
});
});

describe('index as strings', function() {
beforeEach(inject(function($compile, $rootScope) {
scope = $rootScope.$new();
scope.first = 'one';
scope.second = 'two';
scope.active = 'two';
elm = $compile([
'<uib-tabset active="active">',
' <uib-tab index="first" heading="First Tab">',
' first content',
' </uib-tab>',
' <uib-tab index="second" heading="Second Tab">',
' second content',
' </uib-tab>',
'</uib-tabset>'
].join('\n'))(scope);
scope.$apply();
return elm;
}));

it('should set second tab active', function() {
expect(titles().eq(0)).not.toHaveClass('active');
expect(titles().eq(1)).toHaveClass('active');
expect(elm.controller('uibTabset').active).toBe('two');
});

it('should change active on click', function() {
expect(titles().eq(0)).not.toHaveClass('active');
titles().eq(0).find('> a').click();
expect(titles().eq(0)).toHaveClass('active');
expect(titles().eq(1)).not.toHaveClass('active');
expect(elm.controller('uibTabset').active).toBe('one');
});
});

describe('tab callback order', function() {
var execOrder;
beforeEach(inject(function($compile, $rootScope) {
Expand Down

1 comment on commit 26d3995

@SandeepThomas
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @RobJacobs

Please sign in to comment.