react-dd-menu
react-dd-menu copied to clipboard
Menu is closed before menu item click is handled
I must be doing something wrong. If I have the close handler set correctly to set the state of isMenuOpen to false, then the handler registered on the a tag in the menu is never called. If I either don't set the close handler at all (which raises a React error, and breaks functionality) or if I put the setState in a setTimeout, it works as expected.
What am I doing wrong?
Hmm, do you have a code snippet you can send me? It appears to be working correctly from my Examples.
Sure, it's embedded in my project's codebase, so I'll have to break it out when I have some time. Feel free to close the issue in the meantime.
Oh, and thanks for the quick response!
I just did some more experimenting, I think the problem only occurs when animate: false. I think the menu closing animation is providing enough time for the menu item's onClick handler to fire. Without the animation, the DOM element with the click handler is removed before the event can fire.
Note: Setting leaveTimeout and enterTimeout both to 1, and enabling the animation, gets it to work, but without a visible animation. Maybe have animate: false just set those two values to 1 and call it a day? Let me know if you want a PR.
Hmm, lemme look through this code for a bit. I haven't actively worked on this package for about a year, so I'm a bit hazy. You can always set the prop closeOnInsideClick: false which would prevent the autoclose feature when clicking any of these list items. It would then rely on every one of a to also call your function to close the menu.
The timeouts of 1 feel like a kind of hack to me, I'd like to find the base problem in my code first if possible.
Ok, I don't think there is any way around the timeout issue. I'd be good with accepting a PR for it. Otherwise I'll try to get to it later this week.