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

Commit 26d3995

Browse files
committed
feat(tab): allow strings for index
- Allows the use of strings for the tab index and active value on the tabset. Closes #5713 Closes #5827
1 parent 9436b9e commit 26d3995

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ AngularJS version of the tabs directive.
4545
Heading text.
4646

4747
* `index` -
48-
Tab index. Must be unique number.
48+
Tab index. Must be unique number or string.
4949

5050
* `select()`
5151
<small class="badge">$</small> -

Diff for: src/tabs/tabs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ angular.module('ui.bootstrap.tabs', [])
2828
selected.tab.active = true;
2929
ctrl.active = selected.index;
3030
oldIndex = selected.index;
31-
} else if (!selected && angular.isNumber(oldIndex)) {
31+
} else if (!selected && angular.isDefined(oldIndex)) {
3232
ctrl.active = null;
3333
oldIndex = null;
3434
}
@@ -52,7 +52,7 @@ angular.module('ui.bootstrap.tabs', [])
5252
return 0;
5353
});
5454

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

7979
$scope.$watch('tabset.active', function(val) {
80-
if (angular.isNumber(val) && val !== oldIndex) {
80+
if (angular.isDefined(val) && val !== oldIndex) {
8181
ctrl.select(findTabIndex(val));
8282
}
8383
});

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

+35
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,41 @@ describe('tabs', function() {
226226
});
227227
});
228228

229+
describe('index as strings', function() {
230+
beforeEach(inject(function($compile, $rootScope) {
231+
scope = $rootScope.$new();
232+
scope.first = 'one';
233+
scope.second = 'two';
234+
scope.active = 'two';
235+
elm = $compile([
236+
'<uib-tabset active="active">',
237+
' <uib-tab index="first" heading="First Tab">',
238+
' first content',
239+
' </uib-tab>',
240+
' <uib-tab index="second" heading="Second Tab">',
241+
' second content',
242+
' </uib-tab>',
243+
'</uib-tabset>'
244+
].join('\n'))(scope);
245+
scope.$apply();
246+
return elm;
247+
}));
248+
249+
it('should set second tab active', function() {
250+
expect(titles().eq(0)).not.toHaveClass('active');
251+
expect(titles().eq(1)).toHaveClass('active');
252+
expect(elm.controller('uibTabset').active).toBe('two');
253+
});
254+
255+
it('should change active on click', function() {
256+
expect(titles().eq(0)).not.toHaveClass('active');
257+
titles().eq(0).find('> a').click();
258+
expect(titles().eq(0)).toHaveClass('active');
259+
expect(titles().eq(1)).not.toHaveClass('active');
260+
expect(elm.controller('uibTabset').active).toBe('one');
261+
});
262+
});
263+
229264
describe('tab callback order', function() {
230265
var execOrder;
231266
beforeEach(inject(function($compile, $rootScope) {

0 commit comments

Comments
 (0)