@@ -127,9 +127,15 @@ export default class Tabs extends Component {
127
127
}
128
128
129
129
getTabsCount ( ) {
130
- return this . props . children && this . props . children [ 0 ] ?
131
- React . Children . count ( this . props . children [ 0 ] . props . children ) :
132
- 0 ;
130
+ if (
131
+ Array . isArray ( this . props . children ) &&
132
+ Array . isArray ( this . props . children [ 0 ] . props . children )
133
+ ) {
134
+ const tabs = this . props . children [ 0 ] . props . children . filter ( x => x . type === Tab ) ;
135
+ return React . Children . count ( tabs ) ;
136
+ }
137
+
138
+ return 0 ;
133
139
}
134
140
135
141
getPanelsCount ( ) {
@@ -178,25 +184,28 @@ export default class Tabs extends Component {
178
184
return null ;
179
185
}
180
186
181
- const tabRef = ( node ) => { this . tabNodes [ `tabs-${ index } ` ] = node ; } ;
187
+ // Exit early if this is not a tab. That way we can have arbitrary
188
+ // elements anywhere inside <TabList>
189
+ if ( tab . type !== Tab ) {
190
+ return tab ;
191
+ }
192
+
193
+ const key = `tabs-${ index } ` ;
194
+ const tabRef = ( node ) => { this . tabNodes [ key ] = node ; } ;
182
195
const id = this . tabIds [ index ] ;
183
196
const panelId = this . panelIds [ index ] ;
184
197
const selected = state . selectedIndex === index ;
185
198
const focus = selected && state . focus ;
186
199
187
200
index ++ ;
188
201
189
- if ( tab . type === Tab ) {
190
- return cloneElement ( tab , {
191
- tabRef,
192
- id,
193
- panelId,
194
- selected,
195
- focus,
196
- } ) ;
197
- }
198
-
199
- return tab ;
202
+ return cloneElement ( tab , {
203
+ tabRef,
204
+ id,
205
+ panelId,
206
+ selected,
207
+ focus,
208
+ } ) ;
200
209
} ) ,
201
210
} ) ;
202
211
@@ -254,7 +263,7 @@ export default class Tabs extends Component {
254
263
return ;
255
264
}
256
265
257
- const index = [ ] . slice . call ( node . parentNode . children ) . indexOf ( node ) ;
266
+ const index = [ ] . slice . call ( node . parentNode . children ) . filter ( isTabNode ) . indexOf ( node ) ;
258
267
this . setSelected ( index ) ;
259
268
return ;
260
269
}
0 commit comments