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.05k stars 586 forks source link

Is there a custom prop for onClick overlay? #401

Closed karmingc closed 4 years ago

karmingc commented 4 years ago

Hi,

I am currently passing custom props down and am wondering if there is any custom props for closing on clicking the overlay. For e.g, for keydown, we have customOnKeyDown and I can pass my custom close func.

Thanks!

negomi commented 4 years ago

Hey @karmingc,

Yes, I think https://github.com/negomi/react-burger-menu#close-menu-handler should do what you want.

If you use that prop, the menu will not close automatically, but your callback will be called instead so you can handle the close yourself.

karmingc commented 4 years ago

Hi @negomi,

Thank you for your response. Seems there's a typescript issue with that specific prop. Upon further reading in FAQ, I decided to use onStateChange={(state) => this.handleStateChange(state)} which triggers upon state.isOpen === false.

For e.g.

// closeMenu being a custom func
onStateChange={(state) => {
  if (!state.isOpen) {
    closeMenu();
    }
  }}

Hope this helps for further use cases! Thanks for the library as well!