szhsin / react-menu

React component for building accessible menu, dropdown, submenu, context menu, and more.
https://szhsin.github.io/react-menu/
MIT License
1.15k stars 57 forks source link

Conditionally use click vs hover as the trigger for a ControlledMenu and SubMenu #1078

Closed ruchiaa closed 1 year ago

ruchiaa commented 1 year ago

I want to use click to trigger the ControlledMenu and its SubMenus if some condition is true, and hover otherwise. How can I achieve this?

szhsin commented 1 year ago

Here is a sandbox example for your use case.

It uses both useClick and useHover from the package, and a boolean toggle to conditionally apply props to the ControlledMenu.

For submenu, it has an openTrigger prop which controls whether the menu is triggered by click or hover events.

ruchiaa commented 1 year ago

That works! Thank you!