isaacplmann / ngx-contextmenu

An Angular component to show a context menu on an arbitrary component
MIT License
248 stars 91 forks source link

Set a css class active to the parent element #124

Closed gustavobmichel closed 6 years ago

gustavobmichel commented 6 years ago

When you have multiple lines it's difficult to know which line has triggered the context menu. It'd be very useful to have a class on the parent element.

For example: If I have got a table and I have applied the context menu to the tr, when you activate the context menu, the tr could have a css class to show it's currently active.

isaacplmann commented 6 years ago

That's a good idea for a new feature.

Here's a potential workaround in the mean time:

<tr *ngFor="let item of itemList" (contextmenu)="onContextMenu($event, item)" [class.active]="item === activeItem">
activeItem: any;
onContextMenu(event: MouseEvent, item: any) {
  this.activeItem = item;
  this.contextMenuService.next.emit({
    // etc...
  });
}
gustavobmichel commented 6 years ago

Thanks for the quick response.

I implemented it as per your suggestion. The only thing I added was <context-menu (close)="onCloseContextMenu()"> so that it clears the selection once you close the context menu.