Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add native context menu #4338

Closed
axelthat opened this issue Jun 14, 2022 · 43 comments · Fixed by #7535
Closed

[feat] Add native context menu #4338

axelthat opened this issue Jun 14, 2022 · 43 comments · Fixed by #7535
Labels
status: backlog Issue is ready and we can work on it type: breaking change This issue or pull request will introduce a breaking change and requires major version bump type: feature request

Comments

@axelthat
Copy link

axelthat commented Jun 14, 2022

Describe the problem

Native context menu is missing.

Describe the solution you'd like

It would be cool to have native context menu. Electron already supports this.
Screen Shot 2022-06-14 at 7 44 30 PM

Alternatives considered

No response

Additional context

No response

@axelthat axelthat changed the title [feat] [feat] Add native context menu Jun 14, 2022
@amrbashir
Copy link
Member

Electron already supports this.

Can you provide a link for their API?

@axelthat
Copy link
Author

@amrbashir amrbashir added the status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes label Jun 14, 2022
@amrbashir
Copy link
Member

amrbashir commented Jun 14, 2022

Thank you, this API won't ship into tauri v1 and will have to wait for v2 and will need to be implemented upstream first, in muda.

@axelthat
Copy link
Author

Gotcha, thanks!

@martpie
Copy link

martpie commented Jul 26, 2022

Some discord discussion about context menu (a feature I'm much looking forward to use in Tauri, as it is currently a hard-blocker for my project).

Yeah it’s a feature we’re aware of, but no one had the bandwidth to work on yet. It’s also by no means a trivial feature

https://discord.com/channels/616186924390023171/731495047962558564/981896781317144648

Advantages of a context menu:

  • looks native
  • easy sub-menus
  • can overflow out of the window
  • not having to care about accessibility
  • keyboard navigation out of the box
  • etc

@KaKi87
Copy link

KaKi87 commented Aug 6, 2022

Hello,
I would like to expand this feature request to the window menu bar as well.
Thanks

@vdvman1
Copy link

vdvman1 commented Aug 6, 2022

@KaKi87 Window menus are already possible

@KaKi87
Copy link

KaKi87 commented Aug 6, 2022

Isn't this issue about the JavaScript API ?

@vdvman1
Copy link

vdvman1 commented Aug 6, 2022

No, it's about being able to control the native right click context menu, right now the only option is to prevent the default context menu from showing and show a custom HTML menu

@KaKi87
Copy link

KaKi87 commented Aug 6, 2022

Yes, but I thought this issue would be about being able to do it from the JS API (@tauri-apps/api).

@vdvman1
Copy link

vdvman1 commented Aug 6, 2022

The issue doesn't even mention JS
Right now there is no API in JS or in Rust to modify the native context menu

@KaKi87
Copy link

KaKi87 commented Aug 6, 2022

The issue mention an Electron API which is a JS one, which is why I thought what I thought. Nevermind, I'll create separate issues if necessary

@Blatman
Copy link

Blatman commented Sep 24, 2022

+1 for native context menus which would probably be a variation of the window menus already implemented.

In the meantime I'm going to try and use a JS setup which may/may not work. Main issue is getting the accelerator keys going correctly (some work on Safari but not sure about the Tauri webview at this stage) but we'll see ....

https://github.com/Blatman/Custom-Context-Menu

@Dot32Dev
Copy link

Dot32Dev commented Jan 5, 2023

What needs to be implemented in muda? It already has custom context menu capabilities.

@amrbashir amrbashir added status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes status: backlog Issue is ready and we can work on it type: breaking change This issue or pull request will introduce a breaking change and requires major version bump and removed status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes labels Jan 5, 2023
@amrbashir amrbashir added this to Roadmap Jan 5, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Roadmap Jan 5, 2023
@dukeeagle
Copy link

Bumping this! What's the current status of this?

@lucasfernog lucasfernog removed this from Roadmap Apr 5, 2023
@martpie
Copy link

martpie commented May 26, 2023

As the main blocker (muda) seems to be solved, I guess the main issue now is to come up with an API (Rust + JS?) for native menus.

Is it something we can expect for Tauri 2.0? I am not asking to get an exact deadline and I understand the amount of work the team has, but having some sense of roughly when we can expect this would be very helpful.

@FabianLars
Copy link
Member

Very likely not for 2.0, no. We try to keep its scope reasonable small. Also i'm not sure how exactly it will work but i'd imagine it will be implemented as a plugin without many core changes so it may not even have to be coupled with a 2.X minor release.

@goenning
Copy link
Contributor

I love the idea of this feature being a plugin, big +1 from me.

I'll play with muda on my Tauri app and share my progress here! If anyone else is doing the same, please share some gists 😊

@AgCaliva

This comment was marked as off-topic.

@c2r0b
Copy link

c2r0b commented Jul 30, 2023

I am working on a plugin for this (currently supports MacOS only): https://github.com/c2r0b/tauri-plugin-context-menu
screenshot

Edit (2023-12-08): it now supports Windows, MacOS and Linux

@amrbashir amrbashir removed the status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes label Jul 30, 2023
@amrbashir amrbashir moved this from 📬Proposal to 🏗 In progress in Roadmap Jul 30, 2023
@github-project-automation github-project-automation bot moved this to 📬Proposal in Roadmap Jul 30, 2023
@amrbashir
Copy link
Member

We are aware that this feature is long overdue and we have been working on it for a while now, it is almost done and should be in the next 2.0.0-alpha release.

As this requires multiple breaking changes in our stack, it will only be targeted for v2 and won't be backported to v1 as it will require tremendous effort that we would rather spend some where else.

Now we don't want to discourage anyone from tackling this issue for v1, it is definitely possible as a plugin.

@martpie
Copy link

martpie commented Aug 14, 2023

@amrbashir Big Kudos to the Tauri team for this. It seems the 2.0 alpha JS documentation is not complete, do you know if there is / will be some helpers to create context menus from the renderer process? Or is it a main process feature only that needs to be accessed via IPC?

@lucasfernog
Copy link
Member

@martpie for now we only have the Rust API implemented, but soon we'll publish the JS API.

@Sahasrara
Copy link

Sahasrara commented Dec 8, 2023

Is there a JS/TS API still a work in progress? Any ETA (even ballpark quarter)?

@Sahasrara
Copy link

@martpie for now we only have the Rust API implemented, but soon we'll publish the JS API.

Sorry, I just saw this! Is there a separate ticket for the JS/TS api?

@samuelgozi
Copy link

I would also like to know how to use this feature, and if there are bindings for the browser.

@Mehdi-Hp
Copy link

Mehdi-Hp commented May 1, 2024

I am kind of confused by this. If the Rust API is implemented, then where is its docs? And why tauri-plugin-context-menu is listed in Tauri@2 plugins page, when it only works with Tauri@1?

@FabianLars
Copy link
Member

I am kind of confused by this. If the Rust API is implemented, then where is its docs?

Most v2 apis aren't properly documented yet.

And why tauri-plugin-context-menu is listed in Tauri@2 plugins page, when it only works with Tauri@1?

Ah, the headings are a bit confusing, but this section is about community plugins automatically sourced from awesome-tauri (for now).


api wise it's relatively simple. It's mostly re-using the existing menu apis but to show it as a context menu you use the popup method rust / js

@pronebird
Copy link
Contributor

Can you folks explain how to replace the default menu that pops up on right click in webview?

@FabianLars
Copy link
Member

I'm only at my phone rn so i can't go into details but essentially you'll need to listen to the contextmenu event in js, prevent_default it, and then show the tauri context menu.

@martpie
Copy link

martpie commented May 2, 2024

I find the JS API perfect and more simple than calling it from the rust backend, you can see an example usage I have made here:

https://github.com/martpie/museeks/blob/37056d9111aa4293a1784ab4d34beb1f6a06eee5/src/components/PlaylistsNav/PlaylistsNav.tsx#L23-L58

Can you folks explain how to replace the default menu that pops up on right click in webview?

What I did was to disable only for production build, so I can still inspect elements in dev mode, as it is quite useful:

https://github.com/martpie/museeks/blob/37056d9111aa4293a1784ab4d34beb1f6a06eee5/src/components/Events/AppEvents.tsx#L18-L21

@Xiaobaishushu25
Copy link

I would like to know if this context menu supports modifying styles(such as change background color), and if icons are only supported on Mac OS?

@martpie
Copy link

martpie commented May 5, 2024

No, context menus is provided by the OS, no styling is available. The OS may display it as dark or light depending on the global theme selection.

If you need control over stylings, you may need to use a JS library to help you, but you will lose some capabilities, like the context menu getting out of the window, accessibility, etc.

@c2r0b
Copy link

c2r0b commented Sep 20, 2024

I would like to know if this context menu supports modifying styles(such as change background color), and if icons are only supported on Mac OS?

The plugin tauri-plugin-context-menu (made for Tauri v1) now allows on demand light or dark theming.
But that is for MacOS only unfortunately.

@tance77
Copy link

tance77 commented Oct 17, 2024

Hey @FabianLars

tauri-plugin-context-menu is listed on features and recipes for V2 however if you got to the Github repository it looks like it's for V1, but says Tauri V2 support Native Context menus and links back to this Github Issue. I'm a bit confused on what we should be using for Native Context Menus controlled via JS API

EDIT 1:
I did find this https://v2.tauri.app/reference/javascript/api/namespacemenu/

However it's saying only Mac OS is supported if I'm reading this right?

EDIT 2:

Native Context Menus

Here is Native Context Menus for V2 https://v2.tauri.app/reference/javascript/api/namespacemenu/

@FabianLars
Copy link
Member

The section you linked is auto generated from awesome-tauri so i guess we should up the prio of tauri-apps/awesome-tauri#379 (also see my comment above about this i guess #4338 (comment))

However it's saying only Mac OS is supported if I'm reading this right?

Nope, that's also just badly formatted. Some menu item types, like MenuItemIcon at the top, are platform specific. The menu feature as a whole works on all (desktop) platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: backlog Issue is ready and we can work on it type: breaking change This issue or pull request will introduce a breaking change and requires major version bump type: feature request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.