Skip to content

Commit

Permalink
Merge pull request #247 from huumanoid/fix-hidden
Browse files Browse the repository at this point in the history
Fix delayHide issue #246
  • Loading branch information
wwayne authored Jan 30, 2017
2 parents bd3bfb0 + c1222ed commit bb57a5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/decorators/getEffect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Util method to get effect
*/

export default function (target) {
target.prototype.getEffect = function (currentTarget) {
const dataEffect = currentTarget.getAttribute('data-effect')
return dataEffect || this.props.effect || 'float'
}
}

11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import staticMethods from './decorators/staticMethods'
import windowListener from './decorators/windowListener'
import customEvent from './decorators/customEvent'
import isCapture from './decorators/isCapture'
import getEffect from './decorators/getEffect'

/* Utils */
import getPosition from './utils/getPosition'
Expand All @@ -18,7 +19,7 @@ import { parseAria } from './utils/aria'
/* CSS */
import cssStyle from './style'

@staticMethods @windowListener @customEvent @isCapture
@staticMethods @windowListener @customEvent @isCapture @getEffect
class ReactTooltip extends Component {

static propTypes = {
Expand Down Expand Up @@ -161,6 +162,7 @@ class ReactTooltip extends Component {

targetArray.forEach(target => {
const isCaptureMode = this.isCapture(target)
const effect = this.getEffect(target)
if (target.getAttribute('currentItem') === null) {
target.setAttribute('currentItem', 'false')
}
Expand All @@ -172,7 +174,7 @@ class ReactTooltip extends Component {
}

target.addEventListener('mouseenter', this.showTooltip, isCaptureMode)
if (this.state.effect === 'float') {
if (effect === 'float') {
target.addEventListener('mousemove', this.updateTooltip, isCaptureMode)
}
target.addEventListener('mouseleave', this.hideTooltip, isCaptureMode)
Expand Down Expand Up @@ -250,12 +252,15 @@ class ReactTooltip extends Component {
scrollHide = this.props.scrollHide
}

// To prevent previously created timers from triggering
this.clearTimer()

this.setState({
placeholder,
isEmptyTip,
place: e.currentTarget.getAttribute('data-place') || this.props.place || 'top',
type: e.currentTarget.getAttribute('data-type') || this.props.type || 'dark',
effect: switchToSolid && 'solid' || e.currentTarget.getAttribute('data-effect') || this.props.effect || 'float',
effect: switchToSolid && 'solid' || this.getEffect(e.currentTarget),
offset: e.currentTarget.getAttribute('data-offset') || this.props.offset || {},
html: e.currentTarget.getAttribute('data-html')
? e.currentTarget.getAttribute('data-html') === 'true'
Expand Down

0 comments on commit bb57a5b

Please sign in to comment.