Skip to content

Commit e3a95e6

Browse files
committed
fix wrong effect detection during listeners binding
1 parent cf33e9d commit e3a95e6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/decorators/getEffect.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Util method to get effect
3+
*/
4+
5+
export default function (target) {
6+
target.prototype.getEffect = function (currentTarget) {
7+
const dataEffect = currentTarget.getAttribute('data-effect')
8+
return dataEffect || this.props.effect || 'float'
9+
}
10+
}
11+

src/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import staticMethods from './decorators/staticMethods'
99
import windowListener from './decorators/windowListener'
1010
import customEvent from './decorators/customEvent'
1111
import isCapture from './decorators/isCapture'
12+
import getEffect from './decorators/getEffect'
1213

1314
/* Utils */
1415
import getPosition from './utils/getPosition'
@@ -18,7 +19,7 @@ import { parseAria } from './utils/aria'
1819
/* CSS */
1920
import cssStyle from './style'
2021

21-
@staticMethods @windowListener @customEvent @isCapture
22+
@staticMethods @windowListener @customEvent @isCapture @getEffect
2223
class ReactTooltip extends Component {
2324

2425
static propTypes = {
@@ -161,6 +162,7 @@ class ReactTooltip extends Component {
161162

162163
targetArray.forEach(target => {
163164
const isCaptureMode = this.isCapture(target)
165+
const effect = this.getEffect(target)
164166
if (target.getAttribute('currentItem') === null) {
165167
target.setAttribute('currentItem', 'false')
166168
}
@@ -172,7 +174,7 @@ class ReactTooltip extends Component {
172174
}
173175

174176
target.addEventListener('mouseenter', this.showTooltip, isCaptureMode)
175-
if (this.state.effect === 'float') {
177+
if (effect === 'float') {
176178
target.addEventListener('mousemove', this.updateTooltip, isCaptureMode)
177179
}
178180
target.addEventListener('mouseleave', this.hideTooltip, isCaptureMode)
@@ -258,7 +260,7 @@ class ReactTooltip extends Component {
258260
isEmptyTip,
259261
place: e.currentTarget.getAttribute('data-place') || this.props.place || 'top',
260262
type: e.currentTarget.getAttribute('data-type') || this.props.type || 'dark',
261-
effect: switchToSolid && 'solid' || e.currentTarget.getAttribute('data-effect') || this.props.effect || 'float',
263+
effect: switchToSolid && 'solid' || this.getEffect(e.currentTarget),
262264
offset: e.currentTarget.getAttribute('data-offset') || this.props.offset || {},
263265
html: e.currentTarget.getAttribute('data-html')
264266
? e.currentTarget.getAttribute('data-html') === 'true'

0 commit comments

Comments
 (0)