vkbansal / react-contextmenu

Project is no longer maintained
MIT License
1.4k stars 375 forks source link

Feature/hide on leave delay #295

Closed Galkon closed 4 years ago

Galkon commented 4 years ago

This Pull Request introduces a new feature: the ability to delay "hide on leave".

One of my major pain points with the UX of this package was that hideOnLeave triggered instantly, so the slightest movement of my mouse outside the menu would close it. But I also did not want to have to leave the menu open until the user intentionally exits it.

This introduces a new prop to the ContextMenu component called hideOnLeaveDelay. By default it is 0, and if it is 0 it is ignored. You can set it to a millisecond value to delay the actual hiding of the menu, which is controlled using setTimeout inside of the onMouseLeave event that the nav in the render tree of ContextMenu emits. This timeout is cleared whenever the user's mouse re-enters the ContextMenu, or when the user intentionally clicks outside of the menu, as well as when in the componentWillUnmount lifecycle method.

All unit tests pass, with an additional unit test being added to test specific hideOnLeaveDelay behavior.

Galkon commented 4 years ago

Closing until I amend some SubMenu behavior to reflect the same prop