react-dd-menu icon indicating copy to clipboard operation
react-dd-menu copied to clipboard

Menu is closed before menu item click is handled

Open JonAbrams opened this issue 8 years ago • 6 comments

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?

JonAbrams avatar Dec 19 '16 18:12 JonAbrams

Hmm, do you have a code snippet you can send me? It appears to be working correctly from my Examples.

mlaursen avatar Dec 19 '16 21:12 mlaursen

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!

JonAbrams avatar Dec 19 '16 21:12 JonAbrams

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.

JonAbrams avatar Dec 19 '16 23:12 JonAbrams

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.

JonAbrams avatar Dec 19 '16 23:12 JonAbrams

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.

mlaursen avatar Dec 20 '16 01:12 mlaursen

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.

mlaursen avatar Dec 22 '16 14:12 mlaursen