@@ -8,11 +8,19 @@ import ownerDocument from './utils/ownerDocument';
8
8
// TODO: Consider using an ES6 symbol here, once we use babel-runtime.
9
9
const CLICK_WAS_INSIDE = '__click_was_inside' ;
10
10
11
- function suppressRootClose ( event ) {
12
- // Tag the native event to prevent the root close logic on document click.
13
- // This seems safer than using event.nativeEvent.stopImmediatePropagation(),
14
- // which is only supported in IE >= 9.
15
- event . nativeEvent [ CLICK_WAS_INSIDE ] = true ;
11
+ let counter = 0 ;
12
+
13
+ function getSuppressRootClose ( ) {
14
+ let id = CLICK_WAS_INSIDE + '_' + counter ++ ;
15
+ return {
16
+ id,
17
+ suppressRootClose ( event ) {
18
+ // Tag the native event to prevent the root close logic on document click.
19
+ // This seems safer than using event.nativeEvent.stopImmediatePropagation(),
20
+ // which is only supported in IE >= 9.
21
+ event . nativeEvent [ id ] = true ;
22
+ }
23
+ } ;
16
24
}
17
25
18
26
export default class RootCloseWrapper extends React . Component {
@@ -21,6 +29,11 @@ export default class RootCloseWrapper extends React.Component {
21
29
22
30
this . handleDocumentClick = this . handleDocumentClick . bind ( this ) ;
23
31
this . handleDocumentKeyUp = this . handleDocumentKeyUp . bind ( this ) ;
32
+
33
+ let { id, suppressRootClose } = getSuppressRootClose ( ) ;
34
+
35
+ this . _suppressRootId = id ;
36
+ this . _suppressRootClosehHandler = suppressRootClose ;
24
37
}
25
38
26
39
bindRootCloseHandlers ( ) {
@@ -35,7 +48,7 @@ export default class RootCloseWrapper extends React.Component {
35
48
36
49
handleDocumentClick ( e ) {
37
50
// This is now the native event.
38
- if ( e [ CLICK_WAS_INSIDE ] ) {
51
+ if ( e [ this . _suppressRootId ] ) {
39
52
return ;
40
53
}
41
54
@@ -68,14 +81,14 @@ export default class RootCloseWrapper extends React.Component {
68
81
69
82
if ( noWrap ) {
70
83
return React . cloneElement ( child , {
71
- onClick : createChainedFunction ( suppressRootClose , child . props . onClick )
84
+ onClick : createChainedFunction ( this . _suppressRootClosehHandler , child . props . onClick )
72
85
} ) ;
73
86
}
74
87
75
88
// Wrap the child in a new element, so the child won't have to handle
76
89
// potentially combining multiple onClick listeners.
77
90
return (
78
- < div onClick = { suppressRootClose } >
91
+ < div onClick = { this . _suppressRootClosehHandler } >
79
92
{ child }
80
93
</ div >
81
94
) ;
0 commit comments