@@ -75,7 +75,6 @@ class ReactTooltip extends React.Component {
75
75
effect : 'float' , // float or fixed
76
76
show : false ,
77
77
border : false ,
78
- placeholder : '' ,
79
78
offset : { } ,
80
79
extraClass : '' ,
81
80
html : false ,
@@ -87,13 +86,16 @@ class ReactTooltip extends React.Component {
87
86
currentTarget : null , // Current target of mouse event
88
87
ariaProps : parseAria ( props ) , // aria- and role attributes
89
88
isEmptyTip : false ,
90
- disable : false
89
+ disable : false ,
90
+ originTooltip : null ,
91
+ isMultiline : false
91
92
}
92
93
93
94
this . bind ( [
94
95
'showTooltip' ,
95
96
'updateTooltip' ,
96
97
'hideTooltip' ,
98
+ 'getTooltipContent' ,
97
99
'globalRebuild' ,
98
100
'globalShow' ,
99
101
'globalHide' ,
@@ -226,6 +228,26 @@ class ReactTooltip extends React.Component {
226
228
target . removeEventListener ( 'mouseleave' , this . hideTooltip , isCaptureMode )
227
229
}
228
230
231
+ getTooltipContent ( ) {
232
+ const { getContent, children} = this . props
233
+
234
+ // Generate tooltip content
235
+ let content
236
+ if ( getContent ) {
237
+ if ( Array . isArray ( getContent ) ) {
238
+ content = getContent [ 0 ] && getContent [ 0 ] ( )
239
+ } else {
240
+ content = getContent ( )
241
+ }
242
+ }
243
+
244
+ return getTipContent ( this . state . originTooltip , children , content , this . state . isMultiline )
245
+ }
246
+
247
+ isEmptyTip ( placeholder ) {
248
+ return typeof placeholder === 'string' && placeholder === '' || placeholder === null
249
+ }
250
+
229
251
/**
230
252
* When mouse enter, show the tooltip
231
253
*/
@@ -238,22 +260,10 @@ class ReactTooltip extends React.Component {
238
260
}
239
261
// Get the tooltip content
240
262
// calculate in this phrase so that tip width height can be detected
241
- const { children , multiline, getContent} = this . props
263
+ const { multiline, getContent} = this . props
242
264
const originTooltip = e . currentTarget . getAttribute ( 'data-tip' )
243
265
const isMultiline = e . currentTarget . getAttribute ( 'data-multiline' ) || multiline || false
244
266
245
- // Generate tootlip content
246
- let content
247
- if ( getContent ) {
248
- if ( Array . isArray ( getContent ) ) {
249
- content = getContent [ 0 ] && getContent [ 0 ] ( )
250
- } else {
251
- content = getContent ( )
252
- }
253
- }
254
- const placeholder = getTipContent ( originTooltip , children , content , isMultiline )
255
- const isEmptyTip = typeof placeholder === 'string' && placeholder === '' || placeholder === null
256
-
257
267
// If it is focus event or called by ReactTooltip.show, switch to `solid` effect
258
268
const switchToSolid = e instanceof window . FocusEvent || isGlobalCall
259
269
@@ -269,8 +279,8 @@ class ReactTooltip extends React.Component {
269
279
this . clearTimer ( )
270
280
271
281
this . setState ( {
272
- placeholder ,
273
- isEmptyTip ,
282
+ originTooltip : originTooltip ,
283
+ isMultiline : isMultiline ,
274
284
desiredPlace : e . currentTarget . getAttribute ( 'data-place' ) || this . props . place || 'top' ,
275
285
place : e . currentTarget . getAttribute ( 'data-place' ) || this . props . place || 'top' ,
276
286
type : e . currentTarget . getAttribute ( 'data-type' ) || this . props . type || 'dark' ,
@@ -297,9 +307,8 @@ class ReactTooltip extends React.Component {
297
307
if ( this . mount ) {
298
308
const { getContent} = this . props
299
309
const placeholder = getTipContent ( originTooltip , '' , getContent [ 0 ] ( ) , isMultiline )
300
- const isEmptyTip = typeof placeholder === 'string' && placeholder === ''
310
+ const isEmptyTip = this . isEmptyTip ( placeholder )
301
311
this . setState ( {
302
- placeholder,
303
312
isEmptyTip
304
313
} )
305
314
}
@@ -312,13 +321,13 @@ class ReactTooltip extends React.Component {
312
321
* When mouse hover, updatetooltip
313
322
*/
314
323
updateTooltip ( e ) {
315
- const { delayShow, show, isEmptyTip , disable} = this . state
324
+ const { delayShow, show, disable} = this . state
316
325
const { afterShow} = this . props
317
- let { placeholder} = this . state
326
+ const placeholder = this . getTooltipContent ( )
318
327
const delayTime = show ? 0 : parseInt ( delayShow , 10 )
319
328
const eventTarget = e . currentTarget
320
329
321
- if ( isEmptyTip || disable ) return // if the tooltip is empty, disable the tooltip
330
+ if ( this . isEmptyTip ( placeholder ) || disable ) return // if the tooltip is empty, disable the tooltip
322
331
const updateState = ( ) => {
323
332
if ( Array . isArray ( placeholder ) && placeholder . length > 0 || placeholder ) {
324
333
const isInvisible = ! this . state . show
@@ -345,10 +354,11 @@ class ReactTooltip extends React.Component {
345
354
* When mouse leave, hide tooltip
346
355
*/
347
356
hideTooltip ( e , hasTarget ) {
348
- const { delayHide, isEmptyTip , disable} = this . state
357
+ const { delayHide, disable} = this . state
349
358
const { afterHide} = this . props
359
+ const placeholder = this . getTooltipContent ( )
350
360
if ( ! this . mount ) return
351
- if ( isEmptyTip || disable ) return // if the tooltip is empty, disable the tooltip
361
+ if ( this . isEmptyTip ( placeholder ) || disable ) return // if the tooltip is empty, disable the tooltip
352
362
if ( hasTarget ) {
353
363
// Don't trigger other elements belongs to other ReactTooltip
354
364
const targetArray = this . getTargetArray ( this . props . id )
@@ -427,7 +437,9 @@ class ReactTooltip extends React.Component {
427
437
}
428
438
429
439
render ( ) {
430
- const { placeholder, extraClass, html, ariaProps, disable, isEmptyTip} = this . state
440
+ const { extraClass, html, ariaProps, disable} = this . state
441
+ const placeholder = this . getTooltipContent ( )
442
+ const isEmptyTip = this . isEmptyTip ( placeholder )
431
443
let tooltipClass = classname (
432
444
'__react_component_tooltip' ,
433
445
{ 'show' : this . state . show && ! disable && ! isEmptyTip } ,
0 commit comments