question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MenuItems sporadically do not work - child component onClick not working

See original GitHub issue

Hi 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jamaldewittecommented, Dec 29, 2017

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.

1reaction
kgregorycommented, Dec 29, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found