Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onMouseLeave triggers when entering Element

I'm trying to simulate a hover event in React. So I am using onMouseEnter and onMouseLeave that triggers the statechange.

Unfortunately when I first enter the Element with the mouse both methods are triggered...

When I leave the Element only onMouseLeaveis triggered. Does anyone knows why the methodonMouseLeave` is triggered on entering the element.

Here is my Code:

   handleOver(event){
        event.preventDefault();
        console.log('enter');
        if(this.state.open === false){
            this.setState({
                open: true,
                anchorEl: event.currentTarget,
            });
        }
    }
    
    handleLeave(event){
         event.preventDefault();
         console.log('leave');
         if(this.state.open === true){
             this.setState({open: false})
         }
    }
                    <img
                        onMouseEnter={this.handleOver}
                        onMouseLeave={this.handleLeave}
                        src={InfoIcon}
                    />
                    
                    <Popover
                        open={this.state.open}
                        anchorEl={this.state.anchorEl}
                        anchorOrigin={{horizontal: 'right', vertical: 'top'}}
                        targetOrigin={{horizontal: 'left', vertical: 'top'}}
                        onRequestClose={this.handleLeave}
                        muiTheme={darkBaseTheme}
                    />
like image 513
Lorenz Weiß Avatar asked Dec 14 '22 18:12

Lorenz Weiß


1 Answers

Technically, this is not a bug, since the onMouseEnter event is triggered correctly, which causes the Popover component to render with a backdrop over the page, which triggers the onMouseLeave event.

This "issue" is discussed at [Popover] event handlers issue (mouseEnter and mouseLeave) #7680.

Credit goes to konradwww, for listing the following explanation, that leads to the behavior any sane person would expect:

<Popover
style={{ pointerEvents: 'none'}}
...
like image 144
Rocket Appliances Avatar answered Dec 18 '22 00:12

Rocket Appliances