@@ -41,7 +41,7 @@ export class SuiTabset implements AfterContentInit {
4141 throw new Error ( "You cannot have no tabs!" ) ;
4242 }
4343 //For every content header we have managed to find,
44- this . _loadedTabs . forEach ( ( t :SuiTab ) => {
44+ this . _loadedTabs . forEach ( ( t :SuiTab , i : number ) => {
4545 //Assuming they have an associated content
4646 if ( ! t . content ) {
4747 //Link the content header with the content with the same ID excluding ones that are already linked
@@ -56,6 +56,8 @@ export class SuiTabset implements AfterContentInit {
5656 t . content = possibleContents . pop ( ) ;
5757 }
5858
59+ t . index = i ;
60+
5961 //Next observe the content's state to catch any changes made anywhere
6062 t . stateChanged$ . subscribe ( ( t :SuiTab ) => this . tabStateChanged ( t ) ) ;
6163 } ) ;
@@ -81,8 +83,8 @@ export class SuiTabset implements AfterContentInit {
8183 this . _activeTab = tab ;
8284 }
8385 //Otherwise check there are no active tabs
84- else if ( this . _activeTab && ! this . _loadedTabs . filter ( ( tH :SuiTab ) => tH . isActive ) . length ) {
85- this . activateClosestTab ( tab ) ;
86+ else if ( this . _activeTab && ! this . _loadedTabs . find ( ( tH :SuiTab ) => tH . isActive ) ) {
87+ this . activateClosestTab ( this . _activeTab ) ;
8688 }
8789
8890 //Check if the content is now disabled, and if so if is currently active
@@ -114,13 +116,14 @@ export class SuiTabset implements AfterContentInit {
114116 private activateClosestTab ( tab :SuiTab ) {
115117 //Grab a list of all of the loaded tabs that aren't disabled (excluding the one we are leaving)
116118 var availableTabs = this . _loadedTabs
117- . filter ( ( tH :SuiTab ) => ! tH . isDisabled || tH == tab ) ;
119+ . filter ( ( tH :SuiTab ) => ! tH . isDisabled ) ;
118120
119- var tabIndex = availableTabs
120- . findIndex ( ( tH :SuiTab ) => tH == tab ) ;
121+ var tabIndex = tab . index ;
121122
122- //Go to the previous content, unless it is the 1st content.
123- tabIndex += ( tabIndex ? - 1 : 1 ) ;
123+ // Only change the tabIndex if we have to.
124+ if ( tabIndex >= availableTabs . length ) {
125+ tabIndex = availableTabs . length - 1 ;
126+ }
124127
125128 availableTabs [ tabIndex ] . isActive = true ;
126129 //This if we just activated a disabled content, not to worry as it will bubble through
0 commit comments