@@ -69,7 +69,9 @@ class ReactTooltip extends Component {
69
69
eventOff : props . eventOff || null ,
70
70
currentEvent : null , // Current mouse event
71
71
currentTarget : null , // Current target of mouse event
72
- ariaProps : parseAria ( props ) // aria- and role attributes
72
+ ariaProps : parseAria ( props ) , // aria- and role attributes
73
+ isEmptyTip : false ,
74
+ disable : false
73
75
}
74
76
75
77
this . bind ( [
@@ -207,11 +209,6 @@ class ReactTooltip extends Component {
207
209
* When mouse enter, show the tooltip
208
210
*/
209
211
showTooltip ( e , isGlobalCall ) {
210
- const disabled = e . currentTarget . getAttribute ( 'data-tip-disable' )
211
- ? e . currentTarget . getAttribute ( 'data-tip-disable' ) === 'true'
212
- : ( this . props . disable || false )
213
- if ( disabled ) return
214
-
215
212
if ( isGlobalCall ) {
216
213
// Don't trigger other elements belongs to other ReactTooltip
217
214
const targetArray = this . getTargetArray ( this . props . id )
@@ -234,6 +231,7 @@ class ReactTooltip extends Component {
234
231
}
235
232
}
236
233
const placeholder = getTipContent ( originTooltip , content , isMultiline )
234
+ const isEmptyTip = typeof placeholder === 'string' && placeholder === ''
237
235
238
236
// If it is focus event or called by ReactTooltip.show, switch to `solid` effect
239
237
const switchToSolid = e instanceof window . FocusEvent || isGlobalCall
@@ -248,6 +246,7 @@ class ReactTooltip extends Component {
248
246
249
247
this . setState ( {
250
248
placeholder,
249
+ isEmptyTip,
251
250
place : e . currentTarget . getAttribute ( 'data-place' ) || this . props . place || 'top' ,
252
251
type : e . currentTarget . getAttribute ( 'data-type' ) || this . props . type || 'dark' ,
253
252
effect : switchToSolid && 'solid' || e . currentTarget . getAttribute ( 'data-effect' ) || this . props . effect || 'float' ,
@@ -260,7 +259,10 @@ class ReactTooltip extends Component {
260
259
border : e . currentTarget . getAttribute ( 'data-border' )
261
260
? e . currentTarget . getAttribute ( 'data-border' ) === 'true'
262
261
: ( this . props . border || false ) ,
263
- extraClass : e . currentTarget . getAttribute ( 'data-class' ) || this . props . class || ''
262
+ extraClass : e . currentTarget . getAttribute ( 'data-class' ) || this . props . class || '' ,
263
+ disable : e . currentTarget . getAttribute ( 'data-tip-disable' )
264
+ ? e . currentTarget . getAttribute ( 'data-tip-disable' ) === 'true'
265
+ : ( this . props . disable || false )
264
266
} , ( ) => {
265
267
if ( scrollHide ) this . addScrollListener ( e )
266
268
this . updateTooltip ( e )
@@ -270,8 +272,10 @@ class ReactTooltip extends Component {
270
272
if ( this . mount ) {
271
273
const { getContent} = this . props
272
274
const placeholder = getTipContent ( originTooltip , getContent [ 0 ] ( ) , isMultiline )
275
+ const isEmptyTip = typeof placeholder === 'string' && placeholder === ''
273
276
this . setState ( {
274
- placeholder
277
+ placeholder,
278
+ isEmptyTip
275
279
} )
276
280
}
277
281
} , getContent [ 1 ] )
@@ -283,14 +287,14 @@ class ReactTooltip extends Component {
283
287
* When mouse hover, updatetooltip
284
288
*/
285
289
updateTooltip ( e ) {
286
- const { delayShow, show} = this . state
290
+ const { delayShow, show, isEmptyTip , disable } = this . state
287
291
const { afterShow} = this . props
288
292
let { placeholder} = this . state
289
293
const delayTime = show ? 0 : parseInt ( delayShow , 10 )
290
294
const eventTarget = e . currentTarget
291
295
296
+ if ( isEmptyTip || disable ) return // if the tooltip is empty, disable the tooltip
292
297
const updateState = ( ) => {
293
- if ( typeof placeholder === 'string' ) placeholder = placeholder . trim ( )
294
298
if ( Array . isArray ( placeholder ) && placeholder . length > 0 || placeholder ) {
295
299
const isInvisible = ! this . state . show
296
300
this . setState ( {
@@ -316,15 +320,16 @@ class ReactTooltip extends Component {
316
320
* When mouse leave, hide tooltip
317
321
*/
318
322
hideTooltip ( e , hasTarget ) {
323
+ const { delayHide, isEmptyTip, disable} = this . state
324
+ const { afterHide} = this . props
319
325
if ( ! this . mount ) return
326
+ if ( isEmptyTip || disable ) return // if the tooltip is empty, disable the tooltip
320
327
if ( hasTarget ) {
321
328
// Don't trigger other elements belongs to other ReactTooltip
322
329
const targetArray = this . getTargetArray ( this . props . id )
323
330
const isMyElement = targetArray . some ( ele => ele === e . currentTarget )
324
331
if ( ! isMyElement || ! this . state . show ) return
325
332
}
326
- const { delayHide} = this . state
327
- const { afterHide} = this . props
328
333
const resetState = ( ) => {
329
334
const isVisible = this . state . show
330
335
this . setState ( {
@@ -360,7 +365,6 @@ class ReactTooltip extends Component {
360
365
updatePosition ( ) {
361
366
const { currentEvent, currentTarget, place, effect, offset} = this . state
362
367
const node = ReactDOM . findDOMNode ( this )
363
-
364
368
const result = getPosition ( currentEvent , currentTarget , node , place , effect , offset )
365
369
366
370
if ( result . isNewState ) {
@@ -397,10 +401,10 @@ class ReactTooltip extends Component {
397
401
}
398
402
399
403
render ( ) {
400
- const { placeholder, extraClass, html, ariaProps} = this . state
404
+ const { placeholder, extraClass, html, ariaProps, disable , isEmptyTip } = this . state
401
405
let tooltipClass = classname (
402
406
'__react_component_tooltip' ,
403
- { 'show' : this . state . show } ,
407
+ { 'show' : this . state . show && ! disable && ! isEmptyTip } ,
404
408
{ 'border' : this . state . border } ,
405
409
{ 'place-top' : this . state . place === 'top' } ,
406
410
{ 'place-bottom' : this . state . place === 'bottom' } ,
@@ -413,7 +417,6 @@ class ReactTooltip extends Component {
413
417
{ 'type-info' : this . state . type === 'info' } ,
414
418
{ 'type-light' : this . state . type === 'light' }
415
419
)
416
-
417
420
if ( html ) {
418
421
return (
419
422
< div className = { `${ tooltipClass } ${ extraClass } ` }
0 commit comments