@@ -236,7 +236,7 @@ module.exports = React.createClass({
236
236
} ,
237
237
238
238
handleKeyDown ( e ) {
239
- if ( isTabNode ( e . target ) ) {
239
+ if ( this . isTabFromContainer ( e . target ) ) {
240
240
let index = this . state . selectedIndex ;
241
241
let preventDefault = false ;
242
242
@@ -264,7 +264,7 @@ module.exports = React.createClass({
264
264
handleClick ( e ) {
265
265
let node = e . target ;
266
266
do { // eslint-disable-line no-cond-assign
267
- if ( isTabNode ( node ) ) {
267
+ if ( this . isTabFromContainer ( node ) ) {
268
268
if ( isTabDisabled ( node ) ) {
269
269
return ;
270
270
}
@@ -302,6 +302,30 @@ module.exports = React.createClass({
302
302
} ;
303
303
} ,
304
304
305
+ /**
306
+ * Determine if a node from event.target is a Tab element for the current Tabs container.
307
+ * If the clicked element is not a Tab, it returns false.
308
+ * If it finds another Tabs container between the Tab and `this`, it returns false.
309
+ */
310
+ isTabFromContainer ( node ) {
311
+ // return immediately if the clicked element is not a Tab.
312
+ if ( ! isTabNode ( node ) ) {
313
+ return false ;
314
+ }
315
+
316
+ // Check if the first occurrence of a Tabs container is `this` one.
317
+ let nodeAncestor = node . parentElement ;
318
+ const tabsNode = findDOMNode ( this ) ;
319
+ do {
320
+ if ( nodeAncestor === tabsNode ) return true ;
321
+ else if ( nodeAncestor . getAttribute ( 'data-tabs' ) ) break ;
322
+
323
+ nodeAncestor = nodeAncestor . parentElement ;
324
+ } while ( nodeAncestor ) ;
325
+
326
+ return false ;
327
+ } ,
328
+
305
329
render ( ) {
306
330
// This fixes an issue with focus management.
307
331
//
@@ -331,6 +355,7 @@ module.exports = React.createClass({
331
355
) }
332
356
onClick = { this . handleClick }
333
357
onKeyDown = { this . handleKeyDown }
358
+ data-tabs
334
359
>
335
360
{ this . getChildren ( ) }
336
361
</ div >
0 commit comments