This logic is moved into a hook. This is needed for our context menus to close when the user clicks something in reactflow. It needed to be extended to support menus also.