Skip to content

Commit c93ec1b

Browse files
committed
3.2.1
1 parent 8448c93 commit c93ec1b

File tree

4 files changed

+49
-32
lines changed

4 files changed

+49
-32
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
## Change Log
22

3-
### 3.2.0 (2016/09/30 01:09 +00:00)
3+
### 3.2.1 (2016/09/30 09:50 +00:00)
4+
- [#202](https://github.com/wwayne/react-tooltip/pull/202) Hide tooltip when getContent return null or undefined, same for empty… (@wwayne)
5+
- [#201](https://github.com/wwayne/react-tooltip/pull/201) Hide tooltip if the tip is empty or disabled (@wwayne)
6+
7+
### 3.2.0 (2016/09/30 01:10 +00:00)
48
- [#200](https://github.com/wwayne/react-tooltip/pull/200) Remove countTransform because the way of transform calculation is cha… (@wwayne)
59
- [#195](https://github.com/wwayne/react-tooltip/pull/195) Use node parent when calculating offset (@iamdoron)
610

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tooltip",
3-
"version": "3.2.0",
3+
"version": "3.2.1",
44
"description": "react tooltip component",
55
"main": "dist/index.js",
66
"scripts": {

standalone/react-tooltip.js

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
389389
eventOff: props.eventOff || null,
390390
currentEvent: null, // Current mouse event
391391
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
393395
};
394396

395397
_this.bind(['showTooltip', 'updateTooltip', 'hideTooltip', 'globalRebuild', 'globalShow', 'globalHide', 'onWindowResize']);
@@ -559,9 +561,6 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
559561
value: function showTooltip(e, isGlobalCall) {
560562
var _this5 = this;
561563

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-
565564
if (isGlobalCall) {
566565
// Don't trigger other elements belongs to other ReactTooltip
567566
var targetArray = this.getTargetArray(this.props.id);
@@ -581,15 +580,16 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
581580
var isMultiline = e.currentTarget.getAttribute('data-multiline') || multiline || false;
582581

583582
// Generate tootlip content
584-
var content = children;
583+
var content = void 0;
585584
if (getContent) {
586585
if (Array.isArray(getContent)) {
587586
content = getContent[0] && getContent[0]();
588587
} else {
589588
content = getContent();
590589
}
591590
}
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;
593593

594594
// If it is focus event or called by ReactTooltip.show, switch to `solid` effect
595595
var switchToSolid = e instanceof window.FocusEvent || isGlobalCall;
@@ -604,6 +604,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
604604

605605
this.setState({
606606
placeholder: placeholder,
607+
isEmptyTip: isEmptyTip,
607608
place: e.currentTarget.getAttribute('data-place') || this.props.place || 'top',
608609
type: e.currentTarget.getAttribute('data-type') || this.props.type || 'dark',
609610
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
612613
delayShow: e.currentTarget.getAttribute('data-delay-show') || this.props.delayShow || 0,
613614
delayHide: e.currentTarget.getAttribute('data-delay-hide') || this.props.delayHide || 0,
614615
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
616618
}, function () {
617619
if (scrollHide) _this5.addScrollListener(e);
618620
_this5.updateTooltip(e);
@@ -623,8 +625,10 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
623625
var _getContent = _this5.props.getContent;
624626

625627
var _placeholder = (0, _getTipContent2.default)(originTooltip, _getContent[0](), isMultiline);
628+
var _isEmptyTip = typeof _placeholder === 'string' && _placeholder === '';
626629
_this5.setState({
627-
placeholder: _placeholder
630+
placeholder: _placeholder,
631+
isEmptyTip: _isEmptyTip
628632
});
629633
}
630634
}, getContent[1]);
@@ -644,14 +648,16 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
644648
var _state = this.state;
645649
var delayShow = _state.delayShow;
646650
var show = _state.show;
651+
var isEmptyTip = _state.isEmptyTip;
652+
var disable = _state.disable;
647653
var afterShow = this.props.afterShow;
648654
var placeholder = this.state.placeholder;
649655

650656
var delayTime = show ? 0 : parseInt(delayShow, 10);
651657
var eventTarget = e.currentTarget;
652658

659+
if (isEmptyTip || disable) return; // if the tooltip is empty, disable the tooltip
653660
var updateState = function updateState() {
654-
if (typeof placeholder === 'string') placeholder = placeholder.trim();
655661
if (Array.isArray(placeholder) && placeholder.length > 0 || placeholder) {
656662
(function () {
657663
var isInvisible = !_this6.state.show;
@@ -684,7 +690,14 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
684690
value: function hideTooltip(e, hasTarget) {
685691
var _this7 = this;
686692

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+
687699
if (!this.mount) return;
700+
if (isEmptyTip || disable) return; // if the tooltip is empty, disable the tooltip
688701
if (hasTarget) {
689702
// Don't trigger other elements belongs to other ReactTooltip
690703
var targetArray = this.getTargetArray(this.props.id);
@@ -693,9 +706,6 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
693706
});
694707
if (!isMyElement || !this.state.show) return;
695708
}
696-
var delayHide = this.state.delayHide;
697-
var afterHide = this.props.afterHide;
698-
699709
var resetState = function resetState() {
700710
var isVisible = _this7.state.show;
701711
_this7.setState({
@@ -738,15 +748,14 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
738748
value: function updatePosition() {
739749
var _this8 = this;
740750

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;
747757

748758
var node = _reactDom2.default.findDOMNode(this);
749-
750759
var result = (0, _getPosition2.default)(currentEvent, currentTarget, node, place, effect, offset);
751760

752761
if (result.isNewState) {
@@ -790,14 +799,15 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
790799
}, {
791800
key: 'render',
792801
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' });
801811
if (html) {
802812
return _react2.default.createElement('div', _extends({ className: tooltipClass + ' ' + extraClass
803813
}, ariaProps, {
@@ -1207,11 +1217,14 @@ Object.defineProperty(exports, "__esModule", {
12071217
value: true
12081218
});
12091219

1210-
exports.default = function (tip, children, multiline) {
1220+
exports.default = function (tip, children, getContent, multiline) {
12111221
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
12121224

12131225
var regexp = /<br\s*\/?>/;
12141226
if (!multiline || multiline === 'false' || !regexp.test(tip)) {
1227+
// No trim(), so that user can keep their input
12151228
return tip;
12161229
}
12171230

standalone/react-tooltip.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)