Skip to content

Commit

Permalink
Merge pull request #389 from wwayne/current_target_fix
Browse files Browse the repository at this point in the history
fix(isCapture): guard use of currentTarget
  • Loading branch information
aronhelser authored Jun 5, 2018
2 parents 871b77c + 28b8493 commit c44cc2d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/decorators/isCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

export default function (target) {
target.prototype.isCapture = function (currentTarget) {
const dataIsCapture = currentTarget.getAttribute('data-iscapture')
return dataIsCapture && dataIsCapture === 'true' || this.props.isCapture || false
return (currentTarget && currentTarget.getAttribute('data-iscapture') === 'true') || this.props.isCapture || false
}
}
11 changes: 6 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,10 @@ class ReactTooltip extends React.Component {
extraClass: e.currentTarget.getAttribute('data-class') || this.props.class || this.props.className || '',
disable: e.currentTarget.getAttribute('data-tip-disable')
? e.currentTarget.getAttribute('data-tip-disable') === 'true'
: (this.props.disable || false)
: (this.props.disable || false),
currentTarget: e.currentTarget
}, () => {
if (scrollHide) this.addScrollListener(e)
if (scrollHide) this.addScrollListener(this.state.currentTarget)
this.updateTooltip(e)

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

if (this.isEmptyTip(placeholder) || disable) return // if the tooltip is empty, disable the tooltip
const updateState = () => {
Expand Down Expand Up @@ -390,8 +391,8 @@ class ReactTooltip extends React.Component {
* Add scroll eventlistener when tooltip show
* automatically hide the tooltip when scrolling
*/
addScrollListener (e) {
const isCaptureMode = this.isCapture(e.currentTarget)
addScrollListener (currentTarget) {
const isCaptureMode = this.isCapture(currentTarget)
window.addEventListener('scroll', this.hideTooltip, isCaptureMode)
}

Expand Down
14 changes: 7 additions & 7 deletions standalone/react-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,7 @@ Object.defineProperty(exports, "__esModule", {

exports.default = function (target) {
target.prototype.isCapture = function (currentTarget) {
var dataIsCapture = currentTarget.getAttribute('data-iscapture');
return dataIsCapture && dataIsCapture === 'true' || this.props.isCapture || false;
return currentTarget && currentTarget.getAttribute('data-iscapture') === 'true' || this.props.isCapture || false;
};
};

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

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

var placeholder = this.getTooltipContent();
var delayTime = show ? 0 : parseInt(delayShow, 10);
var eventTarget = e.currentTarget;
var eventTarget = e.currentTarget || e.target;

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

}, {
key: 'addScrollListener',
value: function addScrollListener(e) {
var isCaptureMode = this.isCapture(e.currentTarget);
value: function addScrollListener(currentTarget) {
var isCaptureMode = this.isCapture(currentTarget);
window.addEventListener('scroll', this.hideTooltip, isCaptureMode);
}
}, {
Expand Down
5 changes: 2 additions & 3 deletions standalone/react-tooltip.min.js

Large diffs are not rendered by default.

0 comments on commit c44cc2d

Please sign in to comment.