Remove Help option on Block dropdown

46 views
Skip to first unread message

Daniel De La Rosa

unread,
May 29, 2024, 2:26:07 PMMay 29
to Blockly
Hi everyone!

I have a quick question: we do not want to display the default Help option on the native Block dropdowns, has anyone been able to remove just that one menu item? If so, how did you go about it?

Thanks!


Maribeth Moffatt

unread,
May 29, 2024, 2:28:36 PMMay 29
to Blockly
Hi Daniel,

The documentation for how to remove a default context menu option is here. Hope that helps!

Best,
Maribeth

Daniel De La Rosa

unread,
May 29, 2024, 4:35:54 PMMay 29
to Blockly
I figured it out! I had to check that workspace exists:
useEffect(() => {
if (workspace) {
Blockly.ContextMenuRegistry.registry.unregister('blockHelp');
}
}, [workspace]);


Thanks for the help!
Message has been deleted

Maribeth Moffatt

unread,
May 29, 2024, 5:35:31 PMMay 29
to Blockly
the context menu is global, so you only want to run it once per page load. I don't know which framework you're using, but you could be seeing that if the code gets loaded more than once. The workspace existing (I don't know where that variable comes from in your code) is not itself relevant but having the condition may ensure it only runs once, in your particular case.

Alternatively you can:
a) call `getItem` first (also described in the above documentation). if the item isn't registered this function will return null. if so, don't try to unregister it.
b) wrap in a try/catch and do nothing in the catch -- that just means it's already been unregistered so you don't need to do anything else.

Best,
Maribeth

Daniel De La Rosa

unread,
May 30, 2024, 11:12:07 AMMay 30
to Blockly
Makes perfect sense. Added the getItem check and now I am not having any issues, and the Help option is gone. 

Thank you!

Reply all
Reply to author
Forward
0 new messages