negomi / react-burger-menu

:hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations
http://negomi.github.io/react-burger-menu/
MIT License
5.04k stars 582 forks source link

Clicking on menu item does not close the menu #492

Closed robrobac closed 10 months ago

robrobac commented 1 year ago

I didn't find anything in the documentation, I may missed it. When menu is open and user clicks on the navigation item, the menu should close, how to achieve that?

pinkpigeonltd commented 1 year ago

Just add a onClick={() => ctx.toggleMenu()} or whatever the function is you use to open / close the menu to each link elem in your menu.

guidra-rev commented 1 year ago

@pinkpigeonltd How do you close the menu programmatically ?

pinkpigeonltd commented 1 year ago

The inbuilt toggleMenu function does that. The menu provides a context (here, ctx), so ctx.toggleMenu() is the function you need to call to close the menu from anywhere that the context is provided. (Make sure to wrap any part of your app that needs this context, in the context provider. Also ensure that you then import the context. Then you can call the function to close the menu)

stale[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.