Is it possible to control the Context Menu with component state?
Hi there,
I am trying to control the show/hide of the context menu using component state and the 'hidden' property of the IContextualMenuProps but this is not working for me.
Please see this CodePen example.
Thank you for posting the issue @jacksonv1lle
We see the issue, but would need to look at it a bit deeper. Marking as bug for now, and looking at it. Please check back here for updates.
Thanks for the codepen!
@jacksonv1lle Here is an updated codepen which would solve your issue.
Here are the diffs from your codepen
-
If
menuPropsare passed in, then we end up invoking theonMenuClickfunction. Changed your codepen to call the same. -
You were setting the
hidden: falseinside therenderfunction irrespective of the state (probably a typo)
Please let us know if this solves your issue. Un-marking from bug
Hey. Thanks for your help. I didn't see the onMenuClick function so now that's allowing me to invoke my click handler as expected.
But the context menu is still not controlled by the state. If you open the menu and then click away, the menu will close but the state will not change.
@jacksonv1lle, thanks for pointing that out. Another issue to add to the one you mentioned is that the default state of isHidden is set to true, but the ContextualMenu still shows up at page load.
@joschect is currently investigating this (took a brief look and feels it could be related to having to set state in onMenuOpened and onMenuClosed).
The button maintains it's own state by default to simplify creating a contextual menu button. If you want to simply own state, and show/hide a separate contextual menu, you are certainly welcome to. This is how you'd do it if we hadn't baked menu into the button. i.e. the only reason to use the internal button contextual menu is to avoid having to set state yourself.
This is probably something we should consider when looking at the new button as well, @khmakoto
Hi @jacksonv1lle, sorry for the long time before replying again. What @micahgodbolt suggested back in June is one way you could achieve this. Did you have a chance to play with that idea?
This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions to Fabric React!