MenuItems sporadically do not work - child component onClick not working
See original GitHub issueHi all,
First of all thank you for this framework! I have been using it for my project and I have the following issue. I have a Menu component with MenuItems. The MenuItems have children, which have an onClick handler. When I click the menu and click an item fast, sometimes the onClick event just not works. Sometimes it does, sometimes it doesn’t.
Code example:
<Menu key={2}
id="menu-appbar"
anchorEl={anchorEl}
anchorOrigin={{
vertical: "top",
horizontal: "left"
}}
transformOrigin={{
vertical: "top",
horizontal: "left"
}}
open={open}
>
<MenuItem
onClick={() => {
console.log("works");
this.handleCloseMenu();
}}
>
<div onClick={() => {console.log("I sometimes don't work")}} Click </div>
</MenuItem>
</Menu>
I tried removing the clickhandler at MenuItem and it still does not work. I note that the click handler in the MenuItem always seems to work, just not of its children. I use create-react-app 16.2, chrome browser.
Really hoping you can help me out. Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
MenuItems sporadically do not work - child component ...
I have a Menu component with MenuItems. The MenuItems have children, which have an onClick handler. When I click the menu and click...
Read more >span does not firing OnClick inside list react child component
I try it when the parent is button and it works perfectly but when the parent is list it doesn't trigger the child....
Read more >Event delegation - The Modern JavaScript Tutorial
In our case we look for <td> on the way up from the source element. If event.target is not inside any <td> ,...
Read more >Angular components: How to talk to your children and listen to ...
Angular/CLI just adds it for you by default. NgOnInit is, as the name would suggest, a function that is fun when the component...
Read more >Event listeners not working? 3 key areas to troubleshoot
Are your event listeners not working as you'd expect? Here are 3 key areas to troubleshoot to help you get everything triggering as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
But shouldn’t an event bubble from inwards to outwards? Shouldn’t the event handler in the div at least always be called?
Sorry about the questions. I’m still learning so I may very well be doing something wrong, but also spend a lot of hours trying to fix this so really would like to have a solution for this.
Questions like this should be posted on StackOverflow. I was unable to reproduce your behavior with the code snippet provided, see this codesandbox.
I’m going to close this issue. If you revisit your example and can identify a problem with material-ui, please re-open this issue and provide the appropriate information.