ps0604
ps0604

Reputation: 1071

Disable opening context menu in Kendo for Angular

In this StackBlitz, a context menu is opened if the checkbox is true. But if it is false, it should not open. Any ideas how to achieve the latter?

@Component({
    selector: 'my-app',
    template: `
        <div #target>
            Target
        </div>
        <kendo-contextmenu [target]="target" [items]="items">
        </kendo-contextmenu>

        Enable context menu <input type="checkbox" [(ngModel)]="open">
    `
})
export class AppComponent {
    public items: any[] = items;
    open = true;
}

Upvotes: 0

Views: 1537

Answers (2)

spierala
spierala

Reputation: 2699

There is a popupOpen Event:

https://www.telerik.com/kendo-angular-ui/components/menus/api/ContextMenuComponent/#toc-popupopen

You can cancel the event like this in the event callback:

    onPopupOpen($event: ContextMenuPopupEvent) {
        if (condition) {
            $event.preventDefault();
            return;
        }
    }

I tried to fix your stackblitz, but it does not work. Seems like your stackblitz example has very outdated angular and kendo deps. But it works here: with Angular 11.2.6, @progress/kendo-angular-menu": "^3.0.0".

Upvotes: 0

Tzannetos Philippakos
Tzannetos Philippakos

Reputation: 489

There's no code on the contextmenu telling it not to display. try adding an *ngIf="open" to it.

Upvotes: 2

Related Questions