2
votes

in Electron, is there a way to detected the element that the context menu is being clicked on?

menu.append(new MenuItem({ label: 'Automate',visible : ?? }))

I want to enable this menuItem only when it is being clicked on a div with #file as the id.

1

1 Answers

1
votes

The context menu event have a target property.

https://developer.mozilla.org/en-US/docs/Web/Events/contextmenu

element.addEventListener('contextmenu', (clickedElement) => {
  if( clickedElement.target.id === "id"){
    // show menu
   }
}