PerfectMemory / ngx-contextmenu

A context menu component for Angular
https://perfectmemory.github.io/ngx-contextmenu
MIT License
42 stars 12 forks source link

Specification: programmatically open/close a contextmenu #10

Closed sroucheray closed 2 years ago

sroucheray commented 2 years ago

Request 1

As a user of the @perfectmemory/ngx-contextmenu library, I want to be able to open the contextmenu by other mean than the contextmenu event, to make the contextmenu available on Safari iOS which does not support this event see https://developer.mozilla.org/en-US/docs/Web/API/Element/contextmenu_event#browser_compatibility and https://bugs.webkit.org/show_bug.cgi?id=213953. This was requested here https://github.com/PerfectMemory/ngx-contextmenu/issues/8

Request 2

As a user of the @perfectmemory/ngx-contextmenu library, I want to be able to close all contextmenu programmatically, to make sure none of them are displayed when my page layout changes somehow. This was requested here https://github.com/PerfectMemory/ngx-contextmenu/issues/9

Notes

In previous version there was a service that was able to do some kind of this work but it was marked as internal, has been refactored and is not to be used anymore outside the library. Thus it is not documented.

This specification intends to document what we need to add to the library to provide those 2 features.

Implementation

Those usage should work:

The implementation should include code, associated unit tests and documentation with examples.

EDIT: 2023-06-15 add $event property to the example where required

sroucheray commented 2 years ago

Implemented in 8.1.0 and forward ported to 14.1.0

michelebenolli commented 1 year ago

Are you planning to port it in v16?

sroucheray commented 1 year ago

Hi @michelebenolli, it's here https://www.npmjs.com/package/@perfectmemory/ngx-contextmenu?activeTab=versions

michelebenolli commented 1 year ago

Unfortunately, with v16.0.0 I'm still not able to open the menu with left click, following the instructions above

sroucheray commented 1 year ago

Could you provide a stackblitz with a minimum reproduction of your problem ?

michelebenolli commented 1 year ago

https://stackblitz.com/edit/stackblitz-starters-krwtxe?file=src%2Fapp%2Fapp.component.html

sroucheray commented 1 year ago

OK, there is a subtle error in the example. The exact syntax is

  (click)="contextMenu.open($event)"

for mouse events do not forget the $event parameter

  (keydown.enter)="contextMenu.open()"

for keyboard this is not required

sroucheray commented 1 year ago

Proper documentation is here https://perfectmemory.github.io/ngx-contextmenu/?path=/docs/context-menu-documentation-in-a-nutshell--docs#by-reusing-directive

michelebenolli commented 1 year ago

Thank you (: