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.