How do I make submenus appear in the custom menu block?

If you're interested, here's the code for the custom menu block:

So, what I want it to do is if it detects a list in the menu block, it converts the list into a submenu with the first item of the list being the label, the second one being the title of the submenu and the rest being the items of the submenu. Here's an example of what would would be expected here:

I want to use it for a custom right-click menu.

Here's an example from the Colors and Crayons library:

color number
fair hue
X11/W3C name
(3D color spaces)={
fair HSL={
fair hue
fair saturation (HSL)
fair lightness
fair HSL vector
fair HSV={
fair hue
fair saturation (HSV)
fair value (brightness)
fair HSV vector
saturation (HSL)
HSL vector
saturation (HSV)
value (brightness)
HSV vector
RGB (0-255)={
RGB(A) vector
RGB(A) hex

I think he means a block that generates menus with JS, not a custom menu for a block.

I know, but my point was that this is what his block has to put in the menu to get a submenu.

Without submenus, the menus are pretty bland. How can I make one?


I'm not sure why my response didn't solve your problem.

He ask for MenuMorph not custom block dropdown menu...

Ah I see.

Well, @ashtyboi, you could read the code in morphic.js that generates submenus. Basically, each menu item is a key-value pair, and for a submenu, the value in the pair is itself a MenuMorph.

I still need help.

Try to actually look at the source.

Where do I find the part that handles the submenus?

Search for the word "submenu."


How do I give a label to the submenu?

Good question, to which I don't remember the answer, even though I wrote this code originally! There's a field named "title" in a MenuMorph; try setting that?

"Title" just sets the title of the MenuMorph that appears.

What if it's a submenu?

Anyway, the point is, you can read the code as well as I can. Or you can open the browser developer tools, set a breakpoint someplace, and open a menu with a submenu, and poke around.

Same thing happens.

Did you try the most obvious - adding another menu as an item?

 let subMenu = new MenuMorph( item=>result=item);
 subMenu.addItem( "SubOne", "sub1");
 menu.addItem( "SubMenu", subMenu);