leungc70
leungc70

Reputation: 79

Context Menu in Electron

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.

Upvotes: 2

Views: 1377

Answers (1)

LonsomeHell
LonsomeHell

Reputation: 593

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
   }
}

Upvotes: 1

Related Questions