Skip to content

Commit c44cc2d

Browse files
authored
Merge pull request #389 from wwayne/current_target_fix
fix(isCapture): guard use of currentTarget
2 parents 871b77c + 28b8493 commit c44cc2d

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

src/decorators/isCapture.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
export default function (target) {
66
target.prototype.isCapture = function (currentTarget) {
7-
const dataIsCapture = currentTarget.getAttribute('data-iscapture')
8-
return dataIsCapture && dataIsCapture === 'true' || this.props.isCapture || false
7+
return (currentTarget && currentTarget.getAttribute('data-iscapture') === 'true') || this.props.isCapture || false
98
}
109
}

src/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,10 @@ class ReactTooltip extends React.Component {
299299
extraClass: e.currentTarget.getAttribute('data-class') || this.props.class || this.props.className || '',
300300
disable: e.currentTarget.getAttribute('data-tip-disable')
301301
? e.currentTarget.getAttribute('data-tip-disable') === 'true'
302-
: (this.props.disable || false)
302+
: (this.props.disable || false),
303+
currentTarget: e.currentTarget
303304
}, () => {
304-
if (scrollHide) this.addScrollListener(e)
305+
if (scrollHide) this.addScrollListener(this.state.currentTarget)
305306
this.updateTooltip(e)
306307

307308
if (getContent && Array.isArray(getContent)) {
@@ -328,7 +329,7 @@ class ReactTooltip extends React.Component {
328329
const {afterShow} = this.props
329330
const placeholder = this.getTooltipContent()
330331
const delayTime = show ? 0 : parseInt(delayShow, 10)
331-
const eventTarget = e.currentTarget
332+
const eventTarget = e.currentTarget || e.target
332333

333334
if (this.isEmptyTip(placeholder) || disable) return // if the tooltip is empty, disable the tooltip
334335
const updateState = () => {
@@ -390,8 +391,8 @@ class ReactTooltip extends React.Component {
390391
* Add scroll eventlistener when tooltip show
391392
* automatically hide the tooltip when scrolling
392393
*/
393-
addScrollListener (e) {
394-
const isCaptureMode = this.isCapture(e.currentTarget)
394+
addScrollListener (currentTarget) {
395+
const isCaptureMode = this.isCapture(currentTarget)
395396
window.addEventListener('scroll', this.hideTooltip, isCaptureMode)
396397
}
397398

standalone/react-tooltip.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,7 @@ Object.defineProperty(exports, "__esModule", {
13491349

13501350
exports.default = function (target) {
13511351
target.prototype.isCapture = function (currentTarget) {
1352-
var dataIsCapture = currentTarget.getAttribute('data-iscapture');
1353-
return dataIsCapture && dataIsCapture === 'true' || this.props.isCapture || false;
1352+
return currentTarget && currentTarget.getAttribute('data-iscapture') === 'true' || this.props.isCapture || false;
13541353
};
13551354
};
13561355

@@ -1895,9 +1894,10 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
18951894
delayHide: e.currentTarget.getAttribute('data-delay-hide') || this.props.delayHide || 0,
18961895
border: e.currentTarget.getAttribute('data-border') ? e.currentTarget.getAttribute('data-border') === 'true' : this.props.border || false,
18971896
extraClass: e.currentTarget.getAttribute('data-class') || this.props.class || this.props.className || '',
1898-
disable: e.currentTarget.getAttribute('data-tip-disable') ? e.currentTarget.getAttribute('data-tip-disable') === 'true' : this.props.disable || false
1897+
disable: e.currentTarget.getAttribute('data-tip-disable') ? e.currentTarget.getAttribute('data-tip-disable') === 'true' : this.props.disable || false,
1898+
currentTarget: e.currentTarget
18991899
}, function () {
1900-
if (scrollHide) _this5.addScrollListener(e);
1900+
if (scrollHide) _this5.addScrollListener(_this5.state.currentTarget);
19011901
_this5.updateTooltip(e);
19021902

19031903
if (getContent && Array.isArray(getContent)) {
@@ -1934,7 +1934,7 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
19341934

19351935
var placeholder = this.getTooltipContent();
19361936
var delayTime = show ? 0 : parseInt(delayShow, 10);
1937-
var eventTarget = e.currentTarget;
1937+
var eventTarget = e.currentTarget || e.target;
19381938

19391939
if (this.isEmptyTip(placeholder) || disable) return; // if the tooltip is empty, disable the tooltip
19401940
var updateState = function updateState() {
@@ -2009,8 +2009,8 @@ var ReactTooltip = (0, _staticMethods2.default)(_class = (0, _windowListener2.de
20092009

20102010
}, {
20112011
key: 'addScrollListener',
2012-
value: function addScrollListener(e) {
2013-
var isCaptureMode = this.isCapture(e.currentTarget);
2012+
value: function addScrollListener(currentTarget) {
2013+
var isCaptureMode = this.isCapture(currentTarget);
20142014
window.addEventListener('scroll', this.hideTooltip, isCaptureMode);
20152015
}
20162016
}, {

standalone/react-tooltip.min.js

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)