Submenu items on a context menu

I’m using this functionality for creating a context menu. It’s documented for XD but also works for PS.

I’m not successful with creating submenus.

This seems not to work:

<menu>
    <menuitem label="Menu">
        <menu>
            <menuitem label="Submenu"></menuitem>
        </menu>
    </menuitem>
</menu>

Is it even possible?

1 Like

For XD, use a <menu label="Submenu">, rather than a <menu> inside a <menuitem>.

It does not appear this is wired up in Ps. None of our features have needed nested submenus, so it’s likely never come up.

None of our features have needed nested submenus, so it’s likely never come up.

:open_mouth:
I thought you also develop features for third party developers and not only for “your features”.

And if it works in XD why it will not be implemented in PS? I also thought you want almost the same behaviour in all host apps …

You don’t think it will be helpful for having submenus on a right click context menu?

Kerri, I think I misunderstood you as saying “so it will probably never come up”. I understood it as “we never needed it, so it won’t come up (in the future)”. You probably meant that’s why it hasn’t been implemented in the past?

The latter, yes; if there’s no code exercising that path, it’s easy for it to be missed. I do note that although submenus work in XD, I don’t see that submenu support is doc’d anywhere, so submenu support was just luck that the developer thought to add it. Because PS is a different backend, everything has to be wired up again. This will change when we move to a new UI compositing engine in the next few months (this is why some elements will become deprecated in favor of Spectrum UXP). Once that happens, parity is much easier, because we don’t have to have a unique back-end for every single app. That will also unblock animations, transforms, better z-order stacking, etc.

Totally see the value of submenus, of course – just that there’s no test for it, and so it’s easy for one app backend to do “the bare minimum” to support what they know is running on them, and end up with inconsistencies.

Definitely not ruling out submenu support in the future.

I’d like to bring up this request again, as it would be extremely helpful.

I really enjoy using the built-in option for context menus because:

  • It looks like a native OS context menu
  • It can extend beyond the panel boundaries (very useful for smaller panels)
  • It’s quick and easy to set up

Here are two use cases from my plugins:

A submenu option would let me build a cleaner, more compact context menu for both the colors and the “Look” options.

I could also group the “Close”, “Save”, and “Export” options here.

This is already possible on native Photoshop panels, so it seems the functionality just isn’t wired up for UXP plugins.

3 Likes

@samgannaway What do you think?

I am not sure but I think did something like that using mostly undocumented sp-popover. It is not easy to handle but I was able to wrap it into React component which was easier to use. It can go outside of panel boundary. I did not even try sub-levels.

Having default context menu would be the best option.

You’re probably referring to this: Have you tried using Spectrum Web Components yet to build your plugin UI? - #32 by tomzag

While this approach works fine for tooltips, it doesn’t work well for context menus. It behaves more like a modal dialog, where only one window can be open at a time. Nested submenus require multiple layers/windows, which makes it impossible to achieve with this method. And even if it were possible, the implementation would be overly complex and impractical.

1 Like

@Erin_Finnegan Please forward this to the appropriate team. :slight_smile: