Given the following:
render() {
const onMouseOver = (event) => {
this.setState({ isHovering: true });
};
const onMouseOut = (event) => {
this.setState({ isHovering: false });
};
const open = this.state.isHovering ? true : false;
return (
<Nav className={styles.TopNav} bsStyle="pills" activeKey={1}>
<NavDropdown
className={dropDownClasses}
eventKey={1}
open={open}
title="Cards"
id="nav-dropdown"
onMouseEnter={onMouseOver}
onMouseOut={onMouseOut}>
<MenuItem eventKey="1.1">Action</MenuItem>
<MenuItem eventKey="1.2">Another action</MenuItem>
</NavDropdown>
<NavItem className={styles.navLink} eventKey={2}>Blog</NavItem>
</Nav>
);
How do I prevent onMouseOut firing when the mouse is over a child of NavDropdown.
Can I detect if I am over a child in onMouseOut?
The onmouseleave event is only supported by Internet Explorer, for a cross-browser solution, use the onmouseout event. The only difference between the onmouseleave and onmouseout events is that the onmouseout event propagates up the document hierarchy, while the onmouseleave does not.
The mouseover event triggers when the mouse pointer enters the div element, and its child elements. The mouseenter event is only triggered when the mouse pointer enters the div element. The onmousemove event triggers every time the mouse pointer is moved over the div element.
Definition and Usage The onmouseout event occurs when the mouse pointer is moved out of an element, or out of one of its children. Tip: This event is often used together with the onmouseover event, which occurs when the pointer is moved onto an element, or onto one of its children.
Definition and Usage The onmouseover event occurs when the mouse pointer is moved onto an element, or onto one of its children. Tip: This event is often used together with the onmouseout event, which occurs when a user moves the mouse pointer out of an element.
This is not React specific. mouseover
and mouseout
events bubble, so the handler also triggers for children of the element. mouseenter
and mouseleave
don't bubble.
So you should listen to mouseleave
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With