Opening GridContextMenu with both left and right click

I’d like mobile users to be able to open GridContextMenu with touch (left click) while still allowing desktop users to open the menu with right click. After changing a context menu to open with a left click only, I found myself right-clicking the grid instinctively.

There doesn’t seem to be an option to make context menu open with both buttons, but I found a hackish work-around that seems to work on Vaadin 24.4

var dummy = new GridContextMenu<>(g);
var gcm = new GridContextMenu<>(g);
gcm.setOpenOnClick(true);
gcm.addGridContextMenuOpenedListener(e -> dummy.close());
gcm.addItem(...);

By adding a dummy GridContextMenu first and then adding second one, the second menu opens with both left and right clicks. The first menu opens too but the other can be closed programmatically.

Detecting whether a user has a touch screen would also be possible, but I don’t like the idea that user would have to learn to use left click on mobile and right on desktop when I could just accept any click to open the menu.

By default, the context menu opens on right click with pointing devices and with long press on touch devices. So you want it to work without long press instead?

I have an example of somewhat similar use case here: Example of how to open GridContextMenu with the left click on the icon while opening it with the right click elsewhere. · GitHub

In my use case the grid has context menu and rows are also dragged to and from the grid. This is a bit tricky with mobile browsers. In Fennec (android) a long press does a right click, but in Brave (also android) a long press starts dragging and doesn’t open the context menu. The same grid is also used with desktop browsers where I need dragging and context menus to work the way people expect.

The best way I could think of so far is to open context menu with either mouse button. Then Fennec users get context menu with long or short press, Brave uses get it with short press and desktop users with left or right click.