fix(tooltip): don't show tooltips for hidden items

This commit is contained in:
Evan Morikawa 2015-03-12 18:33:49 -04:00
parent 3dbbc6b474
commit 453e449955

View file

@ -47,13 +47,23 @@ Tooltip = React.createClass
# listeners. # listeners.
onMouseOver: (e) -> onMouseOver: (e) ->
target = @_elementWithTooltip(e.target) target = @_elementWithTooltip(e.target)
if target then @_onTooltipEnter(target) if target and @_targetIsVisible(target) then @_onTooltipEnter(target)
else if @state.display then @_hideTooltip() else if @state.display then @_hideTooltip()
onMouseOut: (e) -> onMouseOut: (e) ->
if @_elementWithTooltip(e.fromElement) and not @_elementWithTooltip(e.toElement) if @_elementWithTooltip(e.fromElement) and not @_elementWithTooltip(e.toElement)
@_onTooltipLeave() @_onTooltipLeave()
_targetIsVisible: (target) ->
while target
style = window.getComputedStyle(target)
target = target.parentNode
continue unless style?
# NOTE: opacity must be soft ==
if style.opacity is 0 or style.opacity is "0" or style.visibility is "hidden" or style.display is "none"
return false
return true
_elementWithTooltip: (target) -> _elementWithTooltip: (target) ->
while target while target
break if target?.dataset?.tooltip? break if target?.dataset?.tooltip?