Skip to content

Commit c8a59c6

Browse files
committed
[fixed] OverlayTrigger hover triggers on mousenter/leave
1 parent 852c569 commit c8a59c6

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/OverlayTrigger.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*eslint-disable react/prop-types */
22
import React, { cloneElement } from 'react';
3-
3+
import contains from 'dom-helpers/query/contains';
44
import createChainedFunction from './utils/createChainedFunction';
55
import createContextWrapper from './utils/createContextWrapper';
66
import Overlay from './Overlay';
@@ -126,6 +126,11 @@ const OverlayTrigger = React.createClass({
126126
}
127127
},
128128

129+
componentWillMount() {
130+
this.handleMouseOver = this.handleMouseOverOut.bind(null, this.handleDelayedShow);
131+
this.handleMouseOut = this.handleMouseOverOut.bind(null, this.handleDelayedHide);
132+
},
133+
129134
componentDidMount(){
130135
this._mountNode = document.createElement('div');
131136
React.render(this._overlay, this._mountNode);
@@ -195,8 +200,8 @@ const OverlayTrigger = React.createClass({
195200
'[react-bootstrap] Specifying only the `"hover"` trigger limits the visibilty of the overlay to just mouse users. ' +
196201
'Consider also including the `"focus"` trigger so that touch and keyboard only users can see the overlay as well.');
197202

198-
props.onMouseOver = createChainedFunction(this.handleDelayedShow, this.props.onMouseOver, triggerProps.onMouseOver);
199-
props.onMouseOut = createChainedFunction(this.handleDelayedHide, this.props.onMouseOut, triggerProps.onMouseOut);
203+
props.onMouseOver = createChainedFunction(this.handleMouseOver, this.props.onMouseOver, triggerProps.onMouseOver);
204+
props.onMouseOut = createChainedFunction(this.handleMouseOut, this.props.onMouseOut, triggerProps.onMouseOut);
200205
}
201206

202207
if (isOneOf('focus', this.props.trigger)) {
@@ -250,6 +255,19 @@ const OverlayTrigger = React.createClass({
250255
this._hoverDelay = null;
251256
this.hide();
252257
}, delay);
258+
},
259+
260+
// Simple implementation of mouseEnter and mouseLeave.
261+
// React's built version is broken: https://github.com/facebook/react/issues/4251
262+
// for cases when the trigger is disabled and mouseOut/Over can cause flicker moving
263+
// from one child element to another.
264+
handleMouseOverOut(handler, e){
265+
let target = e.currentTarget;
266+
let related = e.relatedTarget || e.nativeEvent.toElement;
267+
268+
if (!related || related !== target && !contains(target, related)){
269+
handler(e);
270+
}
253271
}
254272

255273
});

0 commit comments

Comments
 (0)