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

Check `disableCloseOnEsc` prop dynamically #317

Closed ivan-aksamentov closed 5 years ago

ivan-aksamentov commented 5 years ago

Currently disableCloseOnEsc prop, which disables closing the menu on ESC is only checked once, on component mount, and the keyboard action is not updated if you reconsider later.

This PR implements a runtime check of the disableCloseOnEsc prop inside the default onkeydown handler (which is now installed regardless of the initial value of disableCloseOnEsc).

This is useful for example for implementing responsive "sicky" behavior, where on larger screens you want to dynamically open the menu, disable ESC key, overlay and mouse click-off, following a media query event.

See discussion in #39

See for example: https://github.com/ivan-aksamentov/example-react-burger-menu-responsive

negomi commented 5 years ago

This makes sense, happy to merge 👍