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