@@ -17,17 +17,17 @@ const handlers = [];
17
17
*/
18
18
export default function onClickOutsideHOC ( WrappedComponent , config ) {
19
19
return class onClickOutside extends Component {
20
- static displayName = `OnClickOutside(${ WrappedComponent . displayName || WrappedComponent . name || 'Component' } )`
20
+ static displayName = `OnClickOutside(${ WrappedComponent . displayName || WrappedComponent . name || 'Component' } )` ;
21
21
22
22
static defaultProps = {
23
23
eventTypes : [ 'mousedown' , 'touchstart' ] ,
24
24
excludeScrollbar : ( config && config . excludeScrollbar ) || false ,
25
25
outsideClickIgnoreClass : 'ignore-react-onclickoutside' ,
26
26
preventDefault : false ,
27
27
stopPropagation : false ,
28
- }
28
+ } ;
29
29
30
- static getClass = ( ) => WrappedComponent . getClass ? WrappedComponent . getClass ( ) : WrappedComponent
30
+ static getClass = ( ) => ( WrappedComponent . getClass ? WrappedComponent . getClass ( ) : WrappedComponent ) ;
31
31
32
32
/**
33
33
* Access the WrappedComponent's instance.
@@ -41,7 +41,7 @@ export default function onClickOutsideHOC(WrappedComponent, config) {
41
41
}
42
42
43
43
// this is given meaning in componentDidMount/componentDidUpdate
44
- __outsideClickHandler = null
44
+ __outsideClickHandler = null ;
45
45
46
46
/**
47
47
* Add click listeners to the current document,
@@ -51,27 +51,31 @@ export default function onClickOutsideHOC(WrappedComponent, config) {
51
51
// If we are in an environment without a DOM such
52
52
// as shallow rendering or snapshots then we exit
53
53
// early to prevent any unhandled errors being thrown.
54
- if ( typeof document === 'undefined' || ! document . createElement ) {
54
+ if ( typeof document === 'undefined' || ! document . createElement ) {
55
55
return ;
56
56
}
57
57
58
58
const instance = this . getInstance ( ) ;
59
59
60
- if ( config && typeof config . handleClickOutside === 'function' ) {
60
+ if ( config && typeof config . handleClickOutside === 'function' ) {
61
61
this . __clickOutsideHandlerProp = config . handleClickOutside ( instance ) ;
62
- if ( typeof this . __clickOutsideHandlerProp !== 'function' ) {
63
- throw new Error ( 'WrappedComponent lacks a function for processing outside click events specified by the handleClickOutside config option.' ) ;
62
+ if ( typeof this . __clickOutsideHandlerProp !== 'function' ) {
63
+ throw new Error (
64
+ 'WrappedComponent lacks a function for processing outside click events specified by the handleClickOutside config option.' ,
65
+ ) ;
64
66
}
65
- } else if ( typeof instance . handleClickOutside === 'function' ) {
67
+ } else if ( typeof instance . handleClickOutside === 'function' ) {
66
68
if ( Component . prototype . isPrototypeOf ( instance ) ) {
67
69
this . __clickOutsideHandlerProp = instance . handleClickOutside . bind ( instance ) ;
68
70
} else {
69
71
this . __clickOutsideHandlerProp = instance . handleClickOutside ;
70
72
}
71
- } else if ( typeof instance . props . handleClickOutside === 'function' ) {
73
+ } else if ( typeof instance . props . handleClickOutside === 'function' ) {
72
74
this . __clickOutsideHandlerProp = instance . props . handleClickOutside ;
73
75
} else {
74
- throw new Error ( 'WrappedComponent lacks a handleClickOutside(event) function for processing outside click events.' ) ;
76
+ throw new Error (
77
+ 'WrappedComponent lacks a handleClickOutside(event) function for processing outside click events.' ,
78
+ ) ;
75
79
}
76
80
77
81
// TODO: try to get rid of this, could be done with function ref, might be problematic for SFC though, they do not expose refs
@@ -132,7 +136,7 @@ export default function onClickOutsideHOC(WrappedComponent, config) {
132
136
document . addEventListener ( eventName , fn , handlerOptions ) ;
133
137
} ) ;
134
138
}
135
- }
139
+ } ;
136
140
137
141
/**
138
142
* Can be called to explicitly disable event listening
@@ -147,17 +151,17 @@ export default function onClickOutsideHOC(WrappedComponent, config) {
147
151
}
148
152
events . forEach ( eventName => document . removeEventListener ( eventName , fn ) ) ;
149
153
}
150
- }
154
+ } ;
151
155
152
156
addOutsideClickHandler ( ) {
153
- const fn = this . __outsideClickHandler = generateOutsideCheck (
157
+ const fn = ( this . __outsideClickHandler = generateOutsideCheck (
154
158
findDOMNode ( this . getInstance ( ) ) ,
155
159
this . __clickOutsideHandlerProp ,
156
160
this . props . outsideClickIgnoreClass ,
157
161
this . props . excludeScrollbar ,
158
162
this . props . preventDefault ,
159
- this . props . stopPropagation
160
- ) ;
163
+ this . props . stopPropagation ,
164
+ ) ) ;
161
165
162
166
const pos = registeredComponents . length ;
163
167
registeredComponents . push ( this ) ;
@@ -178,23 +182,23 @@ export default function onClickOutsideHOC(WrappedComponent, config) {
178
182
179
183
if ( pos > - 1 ) {
180
184
// clean up so we don't leak memory
181
- if ( handlers [ pos ] ) { handlers . splice ( pos , 1 ) ; }
185
+ if ( handlers [ pos ] ) {
186
+ handlers . splice ( pos , 1 ) ;
187
+ }
182
188
registeredComponents . splice ( pos , 1 ) ;
183
189
}
184
190
}
185
191
186
- getRef = ref => this . instanceRef = ref
192
+ getRef = ref => ( this . instanceRef = ref ) ;
187
193
188
194
/**
189
195
* Pass-through render
190
196
*/
191
197
render ( ) {
192
- var props = Object . keys ( this . props )
193
- . filter ( prop => prop !== 'excludeScrollbar' )
194
- . reduce ( ( props , prop ) => {
195
- props [ prop ] = this . props [ prop ] ;
196
- return props ;
197
- } , { } ) ;
198
+ var props = Object . keys ( this . props ) . filter ( prop => prop !== 'excludeScrollbar' ) . reduce ( ( props , prop ) => {
199
+ props [ prop ] = this . props [ prop ] ;
200
+ return props ;
201
+ } , { } ) ;
198
202
199
203
if ( WrappedComponent . prototype . isReactComponent ) {
200
204
props . ref = this . getRef ;
0 commit comments