fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

Is it possible to control the Context Menu with component state?

Open jacksonv1lle opened this issue 7 years ago • 8 comments

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.

jacksonv1lle avatar Jun 19 '19 12:06 jacksonv1lle

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!

aftab-hassan avatar Jun 19 '19 18:06 aftab-hassan

@jacksonv1lle Here is an updated codepen which would solve your issue.

Here are the diffs from your codepen

  1. If menuProps are passed in, then we end up invoking the onMenuClick function. Changed your codepen to call the same.

  2. You were setting the hidden: false inside the render function irrespective of the state (probably a typo)

Please let us know if this solves your issue. Un-marking from bug

aftab-hassan avatar Jun 19 '19 20:06 aftab-hassan

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 avatar Jun 19 '19 20:06 jacksonv1lle

@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).

aftab-hassan avatar Jun 20 '19 19:06 aftab-hassan

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.

micahgodbolt avatar Jun 20 '19 20:06 micahgodbolt

This is probably something we should consider when looking at the new button as well, @khmakoto

micahgodbolt avatar Jul 03 '19 15:07 micahgodbolt

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?

khmakoto avatar Jan 30 '20 01:01 khmakoto

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!

msft-github-bot avatar Feb 03 '20 02:02 msft-github-bot