@@ -389,7 +389,9 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
389
389
eventOff : props . eventOff || null ,
390
390
currentEvent : null , // Current mouse event
391
391
currentTarget : null , // Current target of mouse event
392
- ariaProps : ( 0 , _aria . parseAria ) ( props ) // aria- and role attributes
392
+ ariaProps : ( 0 , _aria . parseAria ) ( props ) , // aria- and role attributes
393
+ isEmptyTip : false ,
394
+ disable : false
393
395
} ;
394
396
395
397
_this . bind ( [ 'showTooltip' , 'updateTooltip' , 'hideTooltip' , 'globalRebuild' , 'globalShow' , 'globalHide' , 'onWindowResize' ] ) ;
@@ -559,9 +561,6 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
559
561
value : function showTooltip ( e , isGlobalCall ) {
560
562
var _this5 = this ;
561
563
562
- var disabled = e . currentTarget . getAttribute ( 'data-tip-disable' ) ? e . currentTarget . getAttribute ( 'data-tip-disable' ) === 'true' : this . props . disable || false ;
563
- if ( disabled ) return ;
564
-
565
564
if ( isGlobalCall ) {
566
565
// Don't trigger other elements belongs to other ReactTooltip
567
566
var targetArray = this . getTargetArray ( this . props . id ) ;
@@ -581,15 +580,16 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
581
580
var isMultiline = e . currentTarget . getAttribute ( 'data-multiline' ) || multiline || false ;
582
581
583
582
// Generate tootlip content
584
- var content = children ;
583
+ var content = void 0 ;
585
584
if ( getContent ) {
586
585
if ( Array . isArray ( getContent ) ) {
587
586
content = getContent [ 0 ] && getContent [ 0 ] ( ) ;
588
587
} else {
589
588
content = getContent ( ) ;
590
589
}
591
590
}
592
- var placeholder = ( 0 , _getTipContent2 . default ) ( originTooltip , content , isMultiline ) ;
591
+ var placeholder = ( 0 , _getTipContent2 . default ) ( originTooltip , children , content , isMultiline ) ;
592
+ var isEmptyTip = typeof placeholder === 'string' && placeholder === '' || placeholder === null ;
593
593
594
594
// If it is focus event or called by ReactTooltip.show, switch to `solid` effect
595
595
var switchToSolid = e instanceof window . FocusEvent || isGlobalCall ;
@@ -604,6 +604,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
604
604
605
605
this . setState ( {
606
606
placeholder : placeholder ,
607
+ isEmptyTip : isEmptyTip ,
607
608
place : e . currentTarget . getAttribute ( 'data-place' ) || this . props . place || 'top' ,
608
609
type : e . currentTarget . getAttribute ( 'data-type' ) || this . props . type || 'dark' ,
609
610
effect : switchToSolid && 'solid' || e . currentTarget . getAttribute ( 'data-effect' ) || this . props . effect || 'float' ,
@@ -612,7 +613,8 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
612
613
delayShow : e . currentTarget . getAttribute ( 'data-delay-show' ) || this . props . delayShow || 0 ,
613
614
delayHide : e . currentTarget . getAttribute ( 'data-delay-hide' ) || this . props . delayHide || 0 ,
614
615
border : e . currentTarget . getAttribute ( 'data-border' ) ? e . currentTarget . getAttribute ( 'data-border' ) === 'true' : this . props . border || false ,
615
- extraClass : e . currentTarget . getAttribute ( 'data-class' ) || this . props . class || ''
616
+ extraClass : e . currentTarget . getAttribute ( 'data-class' ) || this . props . class || '' ,
617
+ disable : e . currentTarget . getAttribute ( 'data-tip-disable' ) ? e . currentTarget . getAttribute ( 'data-tip-disable' ) === 'true' : this . props . disable || false
616
618
} , function ( ) {
617
619
if ( scrollHide ) _this5 . addScrollListener ( e ) ;
618
620
_this5 . updateTooltip ( e ) ;
@@ -623,8 +625,10 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
623
625
var _getContent = _this5 . props . getContent ;
624
626
625
627
var _placeholder = ( 0 , _getTipContent2 . default ) ( originTooltip , _getContent [ 0 ] ( ) , isMultiline ) ;
628
+ var _isEmptyTip = typeof _placeholder === 'string' && _placeholder === '' ;
626
629
_this5 . setState ( {
627
- placeholder : _placeholder
630
+ placeholder : _placeholder ,
631
+ isEmptyTip : _isEmptyTip
628
632
} ) ;
629
633
}
630
634
} , getContent [ 1 ] ) ;
@@ -644,14 +648,16 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
644
648
var _state = this . state ;
645
649
var delayShow = _state . delayShow ;
646
650
var show = _state . show ;
651
+ var isEmptyTip = _state . isEmptyTip ;
652
+ var disable = _state . disable ;
647
653
var afterShow = this . props . afterShow ;
648
654
var placeholder = this . state . placeholder ;
649
655
650
656
var delayTime = show ? 0 : parseInt ( delayShow , 10 ) ;
651
657
var eventTarget = e . currentTarget ;
652
658
659
+ if ( isEmptyTip || disable ) return ; // if the tooltip is empty, disable the tooltip
653
660
var updateState = function updateState ( ) {
654
- if ( typeof placeholder === 'string' ) placeholder = placeholder . trim ( ) ;
655
661
if ( Array . isArray ( placeholder ) && placeholder . length > 0 || placeholder ) {
656
662
( function ( ) {
657
663
var isInvisible = ! _this6 . state . show ;
@@ -684,7 +690,14 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
684
690
value : function hideTooltip ( e , hasTarget ) {
685
691
var _this7 = this ;
686
692
693
+ var _state2 = this . state ;
694
+ var delayHide = _state2 . delayHide ;
695
+ var isEmptyTip = _state2 . isEmptyTip ;
696
+ var disable = _state2 . disable ;
697
+ var afterHide = this . props . afterHide ;
698
+
687
699
if ( ! this . mount ) return ;
700
+ if ( isEmptyTip || disable ) return ; // if the tooltip is empty, disable the tooltip
688
701
if ( hasTarget ) {
689
702
// Don't trigger other elements belongs to other ReactTooltip
690
703
var targetArray = this . getTargetArray ( this . props . id ) ;
@@ -693,9 +706,6 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
693
706
} ) ;
694
707
if ( ! isMyElement || ! this . state . show ) return ;
695
708
}
696
- var delayHide = this . state . delayHide ;
697
- var afterHide = this . props . afterHide ;
698
-
699
709
var resetState = function resetState ( ) {
700
710
var isVisible = _this7 . state . show ;
701
711
_this7 . setState ( {
@@ -738,15 +748,14 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
738
748
value : function updatePosition ( ) {
739
749
var _this8 = this ;
740
750
741
- var _state2 = this . state ;
742
- var currentEvent = _state2 . currentEvent ;
743
- var currentTarget = _state2 . currentTarget ;
744
- var place = _state2 . place ;
745
- var effect = _state2 . effect ;
746
- var offset = _state2 . offset ;
751
+ var _state3 = this . state ;
752
+ var currentEvent = _state3 . currentEvent ;
753
+ var currentTarget = _state3 . currentTarget ;
754
+ var place = _state3 . place ;
755
+ var effect = _state3 . effect ;
756
+ var offset = _state3 . offset ;
747
757
748
758
var node = _reactDom2 . default . findDOMNode ( this ) ;
749
-
750
759
var result = ( 0 , _getPosition2 . default ) ( currentEvent , currentTarget , node , place , effect , offset ) ;
751
760
752
761
if ( result . isNewState ) {
@@ -790,14 +799,15 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
790
799
} , {
791
800
key : 'render' ,
792
801
value : function render ( ) {
793
- var _state3 = this . state ;
794
- var placeholder = _state3 . placeholder ;
795
- var extraClass = _state3 . extraClass ;
796
- var html = _state3 . html ;
797
- var ariaProps = _state3 . ariaProps ;
798
-
799
- var tooltipClass = ( 0 , _classnames2 . default ) ( '__react_component_tooltip' , { 'show' : this . state . show } , { 'border' : this . state . border } , { 'place-top' : this . state . place === 'top' } , { 'place-bottom' : this . state . place === 'bottom' } , { 'place-left' : this . state . place === 'left' } , { 'place-right' : this . state . place === 'right' } , { 'type-dark' : this . state . type === 'dark' } , { 'type-success' : this . state . type === 'success' } , { 'type-warning' : this . state . type === 'warning' } , { 'type-error' : this . state . type === 'error' } , { 'type-info' : this . state . type === 'info' } , { 'type-light' : this . state . type === 'light' } ) ;
800
-
802
+ var _state4 = this . state ;
803
+ var placeholder = _state4 . placeholder ;
804
+ var extraClass = _state4 . extraClass ;
805
+ var html = _state4 . html ;
806
+ var ariaProps = _state4 . ariaProps ;
807
+ var disable = _state4 . disable ;
808
+ var isEmptyTip = _state4 . isEmptyTip ;
809
+
810
+ var tooltipClass = ( 0 , _classnames2 . default ) ( '__react_component_tooltip' , { 'show' : this . state . show && ! disable && ! isEmptyTip } , { 'border' : this . state . border } , { 'place-top' : this . state . place === 'top' } , { 'place-bottom' : this . state . place === 'bottom' } , { 'place-left' : this . state . place === 'left' } , { 'place-right' : this . state . place === 'right' } , { 'type-dark' : this . state . type === 'dark' } , { 'type-success' : this . state . type === 'success' } , { 'type-warning' : this . state . type === 'warning' } , { 'type-error' : this . state . type === 'error' } , { 'type-info' : this . state . type === 'info' } , { 'type-light' : this . state . type === 'light' } ) ;
801
811
if ( html ) {
802
812
return _react2 . default . createElement ( 'div' , _extends ( { className : tooltipClass + ' ' + extraClass
803
813
} , ariaProps , {
@@ -1207,11 +1217,14 @@ Object.defineProperty(exports, "__esModule", {
1207
1217
value : true
1208
1218
} ) ;
1209
1219
1210
- exports . default = function ( tip , children , multiline ) {
1220
+ exports . default = function ( tip , children , getContent , multiline ) {
1211
1221
if ( children ) return children ;
1222
+ if ( getContent !== undefined && getContent !== null ) return getContent ; // getContent can be 0, '', etc.
1223
+ if ( getContent === null ) return null ; // Tip not exist and childern is null or undefined
1212
1224
1213
1225
var regexp = / < b r \s * \/ ? > / ;
1214
1226
if ( ! multiline || multiline === 'false' || ! regexp . test ( tip ) ) {
1227
+ // No trim(), so that user can keep their input
1215
1228
return tip ;
1216
1229
}
1217
1230
0 commit comments