Skip to content

Commit 9e3722c

Browse files
committed
3.1.8
1 parent 2e2483f commit 9e3722c

File tree

4 files changed

+52
-19
lines changed

4 files changed

+52
-19
lines changed

CHANGELOG.md

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

3+
### 3.1.8 (2016/09/14 13:37 +00:00)
4+
- [#194](https://github.com/wwayne/react-tooltip/pull/194) Add resizeHide option (@wwayne)
5+
- [#193](https://github.com/wwayne/react-tooltip/pull/193) hide specific tooltip (@wwayne)
6+
- [#192](https://github.com/wwayne/react-tooltip/pull/192) Create scroll hide option (@wwayne)
7+
38
### 3.1.7 (2016/09/07 00:46 +00:00)
49
- [#187](https://github.com/wwayne/react-tooltip/pull/187) Add disable option (@wwayne)
510
- [#183](https://github.com/wwayne/react-tooltip/pull/183) Remove react-dom from Bower dependencies (@mikkopiu)

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.1.7",
3+
"version": "3.1.8",
44
"description": "react tooltip component",
55
"main": "dist/index.js",
66
"scripts": {

standalone/react-tooltip.js

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ exports.default = function (target) {
179179
* Hide all tooltip
180180
* @trigger ReactTooltip.hide()
181181
*/
182-
target.hide = function () {
183-
dispatchGlobalEvent(_constant2.default.GLOBAL.HIDE);
182+
target.hide = function (target) {
183+
dispatchGlobalEvent(_constant2.default.GLOBAL.HIDE, { target: target });
184184
};
185185

186186
/**
@@ -214,6 +214,13 @@ exports.default = function (target) {
214214
this.showTooltip(e, true);
215215
}
216216
};
217+
218+
target.prototype.globalHide = function (event) {
219+
if (this.mount) {
220+
var hasTarget = event && event.detail && event.detail.target && true || false;
221+
this.hideTooltip({ currentTarget: hasTarget && event.detail.target }, hasTarget);
222+
}
223+
};
217224
};
218225

219226
var _constant = require('../constant');
@@ -247,10 +254,10 @@ Object.defineProperty(exports, "__esModule", {
247254
});
248255

249256
exports.default = function (target) {
250-
target.prototype.bindWindowEvents = function () {
257+
target.prototype.bindWindowEvents = function (resizeHide) {
251258
// ReactTooltip.hide
252-
window.removeEventListener(_constant2.default.GLOBAL.HIDE, this.hideTooltip);
253-
window.addEventListener(_constant2.default.GLOBAL.HIDE, this.hideTooltip, false);
259+
window.removeEventListener(_constant2.default.GLOBAL.HIDE, this.globalHide);
260+
window.addEventListener(_constant2.default.GLOBAL.HIDE, this.globalHide, false);
254261

255262
// ReactTooltip.rebuild
256263
window.removeEventListener(_constant2.default.GLOBAL.REBUILD, this.globalRebuild);
@@ -261,12 +268,14 @@ exports.default = function (target) {
261268
window.addEventListener(_constant2.default.GLOBAL.SHOW, this.globalShow, false);
262269

263270
// Resize
264-
window.removeEventListener('resize', this.onWindowResize);
265-
window.addEventListener('resize', this.onWindowResize, false);
271+
if (resizeHide) {
272+
window.removeEventListener('resize', this.onWindowResize);
273+
window.addEventListener('resize', this.onWindowResize, false);
274+
}
266275
};
267276

268277
target.prototype.unbindWindowEvents = function () {
269-
window.removeEventListener(_constant2.default.GLOBAL.HIDE, this.hideTooltip);
278+
window.removeEventListener(_constant2.default.GLOBAL.HIDE, this.globalHide);
270279
window.removeEventListener(_constant2.default.GLOBAL.REBUILD, this.globalRebuild);
271280
window.removeEventListener(_constant2.default.GLOBAL.SHOW, this.globalShow);
272281
window.removeEventListener('resize', this.onWindowResize);
@@ -383,7 +392,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
383392
ariaProps: (0, _aria.parseAria)(props) // aria- and role attributes
384393
};
385394

386-
_this.bind(['showTooltip', 'updateTooltip', 'hideTooltip', 'globalRebuild', 'globalShow', 'onWindowResize']);
395+
_this.bind(['showTooltip', 'updateTooltip', 'hideTooltip', 'globalRebuild', 'globalShow', 'globalHide', 'onWindowResize']);
387396

388397
_this.mount = true;
389398
_this.delayShowLoop = null;
@@ -411,7 +420,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
411420
value: function componentDidMount() {
412421
this.setStyleHeader(); // Set the style to the <link>
413422
this.bindListener(); // Bind listener for tooltip
414-
this.bindWindowEvents(); // Bind global event for static method
423+
this.bindWindowEvents(this.props.resizeHide); // Bind global event for static method
415424
}
416425
}, {
417426
key: 'componentWillReceiveProps',
@@ -584,6 +593,15 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
584593

585594
// If it is focus event or called by ReactTooltip.show, switch to `solid` effect
586595
var switchToSolid = e instanceof window.FocusEvent || isGlobalCall;
596+
597+
// if it need to skip adding hide listener to scroll
598+
var scrollHide = true;
599+
if (e.currentTarget.getAttribute('data-scroll-hide')) {
600+
scrollHide = e.currentTarget.getAttribute('data-scroll-hide') === 'true';
601+
} else if (this.props.scrollHide != null) {
602+
scrollHide = this.props.scrollHide;
603+
}
604+
587605
this.setState({
588606
placeholder: placeholder,
589607
place: e.currentTarget.getAttribute('data-place') || this.props.place || 'top',
@@ -597,7 +615,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
597615
extraClass: e.currentTarget.getAttribute('data-class') || this.props.class || '',
598616
countTransform: e.currentTarget.getAttribute('data-count-transform') ? e.currentTarget.getAttribute('data-count-transform') === 'true' : this.props.countTransform != null ? this.props.countTransform : true
599617
}, function () {
600-
_this5.addScrollListener(e);
618+
if (scrollHide) _this5.addScrollListener(e);
601619
_this5.updateTooltip(e);
602620

603621
if (getContent && Array.isArray(getContent)) {
@@ -664,15 +682,21 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
664682

665683
}, {
666684
key: 'hideTooltip',
667-
value: function hideTooltip() {
685+
value: function hideTooltip(e, hasTarget) {
668686
var _this7 = this;
669687

688+
if (!this.mount) return;
689+
if (hasTarget) {
690+
// Don't trigger other elements belongs to other ReactTooltip
691+
var targetArray = this.getTargetArray(this.props.id);
692+
var isMyElement = targetArray.some(function (ele) {
693+
return ele === e.currentTarget;
694+
});
695+
if (!isMyElement || !this.state.show) return;
696+
}
670697
var delayHide = this.state.delayHide;
671698
var afterHide = this.props.afterHide;
672699

673-
674-
if (!this.mount) return;
675-
676700
var resetState = function resetState() {
677701
var isVisible = _this7.state.show;
678702
_this7.setState({
@@ -816,7 +840,11 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
816840
countTransform: _react.PropTypes.bool,
817841
afterShow: _react.PropTypes.func,
818842
afterHide: _react.PropTypes.func,
819-
disable: _react.PropTypes.bool
843+
disable: _react.PropTypes.bool,
844+
scrollHide: _react.PropTypes.bool,
845+
resizeHide: _react.PropTypes.bool
846+
}, _class2.defaultProps = {
847+
resizeHide: true
820848
}, _temp)) || _class) || _class) || _class) || _class;
821849

822850
/* export default not fit for standalone, it will exports {default:...} */

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)