This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree 3 files changed +39
-4
lines changed
3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ AngularJS version of the tabs directive.
45
45
Heading text.
46
46
47
47
* ` index ` -
48
- Tab index. Must be unique number.
48
+ Tab index. Must be unique number or string .
49
49
50
50
* ` select() `
51
51
<small class =" badge " >$</small > -
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ angular.module('ui.bootstrap.tabs', [])
28
28
selected . tab . active = true ;
29
29
ctrl . active = selected . index ;
30
30
oldIndex = selected . index ;
31
- } else if ( ! selected && angular . isNumber ( oldIndex ) ) {
31
+ } else if ( ! selected && angular . isDefined ( oldIndex ) ) {
32
32
ctrl . active = null ;
33
33
oldIndex = null ;
34
34
}
@@ -52,7 +52,7 @@ angular.module('ui.bootstrap.tabs', [])
52
52
return 0 ;
53
53
} ) ;
54
54
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 ) {
56
56
var newActiveIndex = findTabIndex ( tab . index ) ;
57
57
ctrl . select ( newActiveIndex ) ;
58
58
}
@@ -77,7 +77,7 @@ angular.module('ui.bootstrap.tabs', [])
77
77
} ;
78
78
79
79
$scope . $watch ( 'tabset.active' , function ( val ) {
80
- if ( angular . isNumber ( val ) && val !== oldIndex ) {
80
+ if ( angular . isDefined ( val ) && val !== oldIndex ) {
81
81
ctrl . select ( findTabIndex ( val ) ) ;
82
82
}
83
83
} ) ;
Original file line number Diff line number Diff line change @@ -226,6 +226,41 @@ describe('tabs', function() {
226
226
} ) ;
227
227
} ) ;
228
228
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
+
229
264
describe ( 'tab callback order' , function ( ) {
230
265
var execOrder ;
231
266
beforeEach ( inject ( function ( $compile , $rootScope ) {
You can’t perform that action at this time.
0 commit comments