Angular Material: How do I disable right click on cdk overlay container?

Viewed 942

I am using a mat-menu as contextmenu on a canvas object, the problem is when I right click the canvas object, the default browser contextmenu showed up, which it overlaped the actual contextmenu; I want to prevent the default contextmenu showing on the cdk-overlay-container element. The right click event is triggered from the child component(canvas) and I have called the preventDefault(), and the mat-menu is in the parent component.

1 Answers

That worked for me

@ViewChild("contextMenu") contextMenu: MatMenu;
...
document.getElementsByClassName(this.contextMenu.backdropClass).item(0)
                .addEventListener("contextmenu", event => {event.preventDefault()});
Related