@@ -10,6 +10,7 @@ import windowListener from './decorators/windowListener'
10
10
import customEvent from './decorators/customEvent'
11
11
import isCapture from './decorators/isCapture'
12
12
import getEffect from './decorators/getEffect'
13
+ import bodyMode from './decorators/bodyMode'
13
14
import trackRemoval from './decorators/trackRemoval'
14
15
15
16
/* Utils */
@@ -26,6 +27,7 @@ import cssStyle from './style'
26
27
@customEvent
27
28
@isCapture
28
29
@getEffect
30
+ @bodyMode
29
31
@trackRemoval
30
32
class ReactTooltip extends React . Component {
31
33
@@ -58,6 +60,9 @@ class ReactTooltip extends React.Component {
58
60
scrollHide : PropTypes . bool ,
59
61
resizeHide : PropTypes . bool ,
60
62
wrapper : PropTypes . string ,
63
+ bodyMode : PropTypes . bool ,
64
+ possibleCustomEvents : PropTypes . string ,
65
+ possibleCustomEventsOff : PropTypes . string ,
61
66
clickable : PropTypes . bool
62
67
} ;
63
68
@@ -93,6 +98,8 @@ class ReactTooltip extends React.Component {
93
98
ariaProps : parseAria ( props ) , // aria- and role attributes
94
99
isEmptyTip : false ,
95
100
disable : false ,
101
+ possibleCustomEvents : props . possibleCustomEvents || '' ,
102
+ possibleCustomEventsOff : props . possibleCustomEventsOff || '' ,
96
103
originTooltip : null ,
97
104
isMultiline : false
98
105
}
@@ -131,6 +138,7 @@ class ReactTooltip extends React.Component {
131
138
if ( insecure ) {
132
139
this . setStyleHeader ( ) // Set the style to the <link>
133
140
}
141
+
134
142
this . bindListener ( ) // Bind listener for tooltip
135
143
this . bindWindowEvents ( resizeHide ) // Bind global event for static method
136
144
}
@@ -206,25 +214,34 @@ class ReactTooltip extends React.Component {
206
214
let targetArray = this . getTargetArray ( id )
207
215
208
216
targetArray . forEach ( target => {
209
- const isCaptureMode = this . isCapture ( target )
210
- const effect = this . getEffect ( target )
211
217
if ( target . getAttribute ( 'currentItem' ) === null ) {
212
218
target . setAttribute ( 'currentItem' , 'false' )
213
219
}
214
220
this . unbindBasicListener ( target )
215
-
216
221
if ( this . isCustomEvent ( target ) ) {
217
- this . customBindListener ( target )
218
- return
219
- }
220
-
221
- target . addEventListener ( 'mouseenter' , this . showTooltip , isCaptureMode )
222
- if ( effect === 'float' ) {
223
- target . addEventListener ( 'mousemove' , this . updateTooltip , isCaptureMode )
222
+ this . customUnbindListener ( target )
224
223
}
225
- target . addEventListener ( 'mouseleave' , this . hideTooltip , isCaptureMode )
226
224
} )
227
225
226
+ if ( this . isBodyMode ( ) ) {
227
+ this . bindBodyListener ( targetArray )
228
+ } else {
229
+ targetArray . forEach ( target => {
230
+ const isCaptureMode = this . isCapture ( target )
231
+ const effect = this . getEffect ( target )
232
+ if ( this . isCustomEvent ( target ) ) {
233
+ this . customBindListener ( target )
234
+ return
235
+ }
236
+
237
+ target . addEventListener ( 'mouseenter' , this . showTooltip , isCaptureMode )
238
+ if ( effect === 'float' ) {
239
+ target . addEventListener ( 'mousemove' , this . updateTooltip , isCaptureMode )
240
+ }
241
+ target . addEventListener ( 'mouseleave' , this . hideTooltip , isCaptureMode )
242
+ } )
243
+ }
244
+
228
245
// Global event to hide tooltip
229
246
if ( globalEventOff ) {
230
247
window . removeEventListener ( globalEventOff , this . hideTooltip )
@@ -240,11 +257,15 @@ class ReactTooltip extends React.Component {
240
257
*/
241
258
unbindListener ( ) {
242
259
const { id, globalEventOff} = this . props
243
- const targetArray = this . getTargetArray ( id )
244
- targetArray . forEach ( target => {
245
- this . unbindBasicListener ( target )
246
- if ( this . isCustomEvent ( target ) ) this . customUnbindListener ( target )
247
- } )
260
+ if ( this . isBodyMode ( ) ) {
261
+ this . unbindBodyListener ( )
262
+ } else {
263
+ const targetArray = this . getTargetArray ( id )
264
+ targetArray . forEach ( target => {
265
+ this . unbindBasicListener ( target )
266
+ if ( this . isCustomEvent ( target ) ) this . customUnbindListener ( target )
267
+ } )
268
+ }
248
269
249
270
if ( globalEventOff ) window . removeEventListener ( globalEventOff , this . hideTooltip )
250
271
this . unbindRemovalTracker ( )
0 commit comments