@@ -59,7 +59,6 @@ class ReactTooltip extends Component {
59
59
effect : 'float' , // float or fixed
60
60
show : false ,
61
61
border : false ,
62
- placeholder : '' ,
63
62
offset : { } ,
64
63
extraClass : '' ,
65
64
html : false ,
@@ -71,13 +70,16 @@ class ReactTooltip extends Component {
71
70
currentTarget : null , // Current target of mouse event
72
71
ariaProps : parseAria ( props ) , // aria- and role attributes
73
72
isEmptyTip : false ,
74
- disable : false
73
+ disable : false ,
74
+ originTooltip : null ,
75
+ isMultiline : false
75
76
}
76
77
77
78
this . bind ( [
78
79
'showTooltip' ,
79
80
'updateTooltip' ,
80
81
'hideTooltip' ,
82
+ 'getTooltipContent' ,
81
83
'globalRebuild' ,
82
84
'globalShow' ,
83
85
'globalHide' ,
@@ -205,6 +207,26 @@ class ReactTooltip extends Component {
205
207
target . removeEventListener ( 'mouseleave' , this . hideTooltip )
206
208
}
207
209
210
+ getTooltipContent ( ) {
211
+ const { getContent, children} = this . props
212
+
213
+ // Generate tooltip content
214
+ let content
215
+ if ( getContent ) {
216
+ if ( Array . isArray ( getContent ) ) {
217
+ content = getContent [ 0 ] && getContent [ 0 ] ( )
218
+ } else {
219
+ content = getContent ( )
220
+ }
221
+ }
222
+
223
+ return getTipContent ( this . state . originTooltip , children , content , this . state . isMultiline )
224
+ }
225
+
226
+ isEmptyTip ( placeholder ) {
227
+ return typeof placeholder === 'string' && placeholder === '' || placeholder === null
228
+ }
229
+
208
230
/**
209
231
* When mouse enter, show the tooltip
210
232
*/
@@ -217,22 +239,10 @@ class ReactTooltip extends Component {
217
239
}
218
240
// Get the tooltip content
219
241
// calculate in this phrase so that tip width height can be detected
220
- const { children , multiline, getContent } = this . props
242
+ const { multiline} = this . props
221
243
const originTooltip = e . currentTarget . getAttribute ( 'data-tip' )
222
244
const isMultiline = e . currentTarget . getAttribute ( 'data-multiline' ) || multiline || false
223
245
224
- // Generate tootlip content
225
- let content
226
- if ( getContent ) {
227
- if ( Array . isArray ( getContent ) ) {
228
- content = getContent [ 0 ] && getContent [ 0 ] ( )
229
- } else {
230
- content = getContent ( )
231
- }
232
- }
233
- const placeholder = getTipContent ( originTooltip , children , content , isMultiline )
234
- const isEmptyTip = typeof placeholder === 'string' && placeholder === '' || placeholder === null
235
-
236
246
// If it is focus event or called by ReactTooltip.show, switch to `solid` effect
237
247
const switchToSolid = e instanceof window . FocusEvent || isGlobalCall
238
248
@@ -245,8 +255,8 @@ class ReactTooltip extends Component {
245
255
}
246
256
247
257
this . setState ( {
248
- placeholder ,
249
- isEmptyTip ,
258
+ originTooltip : originTooltip ,
259
+ isMultiline : isMultiline ,
250
260
place : e . currentTarget . getAttribute ( 'data-place' ) || this . props . place || 'top' ,
251
261
type : e . currentTarget . getAttribute ( 'data-type' ) || this . props . type || 'dark' ,
252
262
effect : switchToSolid && 'solid' || e . currentTarget . getAttribute ( 'data-effect' ) || this . props . effect || 'float' ,
@@ -266,34 +276,20 @@ class ReactTooltip extends Component {
266
276
} , ( ) => {
267
277
if ( scrollHide ) this . addScrollListener ( e )
268
278
this . updateTooltip ( e )
269
-
270
- if ( getContent && Array . isArray ( getContent ) ) {
271
- this . intervalUpdateContent = setInterval ( ( ) => {
272
- if ( this . mount ) {
273
- const { getContent} = this . props
274
- const placeholder = getTipContent ( originTooltip , getContent [ 0 ] ( ) , isMultiline )
275
- const isEmptyTip = typeof placeholder === 'string' && placeholder === ''
276
- this . setState ( {
277
- placeholder,
278
- isEmptyTip
279
- } )
280
- }
281
- } , getContent [ 1 ] )
282
- }
283
279
} )
284
280
}
285
281
286
282
/**
287
283
* When mouse hover, updatetooltip
288
284
*/
289
285
updateTooltip ( e ) {
290
- const { delayShow, show, isEmptyTip , disable} = this . state
286
+ const { delayShow, show, disable} = this . state
291
287
const { afterShow} = this . props
292
- let { placeholder} = this . state
288
+ const placeholder = this . getTooltipContent ( )
293
289
const delayTime = show ? 0 : parseInt ( delayShow , 10 )
294
290
const eventTarget = e . currentTarget
295
291
296
- if ( isEmptyTip || disable ) return // if the tooltip is empty, disable the tooltip
292
+ if ( this . isEmptyTip ( placeholder ) || disable ) return // if the tooltip is empty, disable the tooltip
297
293
const updateState = ( ) => {
298
294
if ( Array . isArray ( placeholder ) && placeholder . length > 0 || placeholder ) {
299
295
const isInvisible = ! this . state . show
@@ -320,10 +316,11 @@ class ReactTooltip extends Component {
320
316
* When mouse leave, hide tooltip
321
317
*/
322
318
hideTooltip ( e , hasTarget ) {
323
- const { delayHide, isEmptyTip , disable} = this . state
319
+ const { delayHide, disable} = this . state
324
320
const { afterHide} = this . props
321
+ const placeholder = this . getTooltipContent ( )
325
322
if ( ! this . mount ) return
326
- if ( isEmptyTip || disable ) return // if the tooltip is empty, disable the tooltip
323
+ if ( this . isEmptyTip ( placeholder ) || disable ) return // if the tooltip is empty, disable the tooltip
327
324
if ( hasTarget ) {
328
325
// Don't trigger other elements belongs to other ReactTooltip
329
326
const targetArray = this . getTargetArray ( this . props . id )
@@ -401,7 +398,9 @@ class ReactTooltip extends Component {
401
398
}
402
399
403
400
render ( ) {
404
- const { placeholder, extraClass, html, ariaProps, disable, isEmptyTip} = this . state
401
+ const { extraClass, html, ariaProps, disable} = this . state
402
+ const placeholder = this . getTooltipContent ( )
403
+ const isEmptyTip = this . isEmptyTip ( placeholder )
405
404
let tooltipClass = classname (
406
405
'__react_component_tooltip' ,
407
406
{ 'show' : this . state . show && ! disable && ! isEmptyTip } ,
0 commit comments