npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ng2-right-click-context-menu

v2.0.0

Published

Right click context menu for Angular

Readme

ng2-right-click-context-menu

A lightweight, flexible right-click context menu library for Angular, built on top of Angular CDK Overlay. Supports nested submenus, dividers, conditional visibility, custom triggers, and per-item data binding.

Requirements

| Library version | Angular version | |-----------------|-----------------| | 2.x | 20+ | | 1.x | 13 – 19 |

Installation

npm install ng2-right-click-context-menu @angular/cdk

Add the CDK overlay styles to your styles.css:

@import "@angular/cdk/overlay-prebuilt.css";

Setup

Standalone component

import { ShContextMenuModule } from 'ng2-right-click-context-menu';

@Component({
  standalone: true,
  imports: [ShContextMenuModule],
  ...
})
export class AppComponent {}

NgModule

import { ShContextMenuModule } from 'ng2-right-click-context-menu';

@NgModule({
  imports: [ShContextMenuModule],
})
export class AppModule {}

Basic Usage

Template

<!-- Attach the menu to any element -->
<div [shAttachMenu]="myMenu" [shMenuData]="item" *ngFor="let item of items">
  Right-click me
</div>

<!-- Define the menu -->
<sh-context-menu #myMenu>
  <ng-template shContextMenuItem let-item (click)="onEdit($event)">
    <span>Edit</span>
  </ng-template>

  <ng-template shContextMenuItem let-item (click)="onDelete($event)">
    <span>Delete</span>
  </ng-template>
</sh-context-menu>

Component

import { Component } from '@angular/core';
import { ShContextMenuModule } from 'ng2-right-click-context-menu';

@Component({
  standalone: true,
  imports: [ShContextMenuModule],
  templateUrl: './app.component.html',
})
export class AppComponent {
  items = [{ label: 'Item 1' }, { label: 'Item 2' }];

  onEdit(event: any) {
    console.log('Edit', event.data);
  }

  onDelete(event: any) {
    console.log('Delete', event.data);
  }
}

Features

Divider

<sh-context-menu #menu>
  <ng-template shContextMenuItem let-item (click)="onCopy($event)">
    <span>Copy</span>
  </ng-template>

  <div shContextMenuItem [divider]="true"></div>

  <ng-template shContextMenuItem let-item (click)="onDelete($event)">
    <span>Delete</span>
  </ng-template>
</sh-context-menu>

Conditional Visibility

Use the [visible] input to show or hide items based on the row data.

<ng-template shContextMenuItem let-item [visible]="canEdit" (click)="onEdit($event)">
  <span>Edit</span>
</ng-template>
canEdit = (event: any) => event.data.editable === true;

Nested Submenus

<sh-context-menu #menu>
  <ng-template shContextMenuItem let-item [subMenu]="colorMenu">
    <span>Change Color</span>
  </ng-template>

  <sh-context-menu #colorMenu>
    <ng-template shContextMenuItem let-item (click)="setColor($event, 'red')">
      <span>Red</span>
    </ng-template>
    <ng-template shContextMenuItem let-item (click)="setColor($event, 'blue')">
      <span>Blue</span>
    </ng-template>
  </sh-context-menu>
</sh-context-menu>

Custom Triggers

By default the menu opens on contextmenu (right-click). Use [shMenuTriggers] to override.

<div [shAttachMenu]="menu" [shMenuTriggers]="['click', 'dblclick']">
  Click or double-click me
</div>

Prevent Open

Use the (open) event to conditionally prevent the menu from opening.

<div [shAttachMenu]="menu" [shMenuData]="item" (open)="onOpen($event)">
  ...
</div>
onOpen(event: ContextOpenEvent) {
  if (event.data.locked) {
    event.preventOpen();
  }
}

[this] Context Binding

Pass the component instance to [this] so that (click) handlers have the correct this context.

<sh-context-menu #menu [this]="thisContext">
  ...
</sh-context-menu>
thisContext = this;

API Reference

ShAttachMenuDirective[shAttachMenu]

| Input / Output | Type | Description | |--------------------|--------------------------|------------------------------------------------------| | [shAttachMenu] | ShContextMenuComponent | The menu to open | | [shMenuData] | any | Data passed to each menu item as let-item | | [shMenuTriggers] | string[] | DOM events that open the menu (default: right-click) | | (open) | ContextOpenEvent | Emitted before the menu opens; call preventOpen() to cancel |

ShContextMenuComponent<sh-context-menu>

| Input | Type | Description | |----------|-------|----------------------------------------------------------| | [this] | any | Component instance for (click) handler context |

ShContextMenuItemDirectiveshContextMenuItem

| Input / Output | Type | Description | |------------------|-----------------------------------------------|--------------------------------------| | [subMenu] | ShContextMenuComponent | Nested submenu to open on hover | | [divider] | boolean | Renders a divider instead of an item | | [visible] | (event: ShContextMenuClickEvent) => boolean | Controls item visibility | | [disabled] | (event: ShContextMenuClickEvent) => boolean | Controls item disabled state | | [closeOnClick] | boolean (default: true) | Whether clicking closes the menu | | (click) | ShContextMenuClickEvent | Emitted when the item is clicked |

ShContextMenuClickEvent

{
  data: any;         // value passed via [shMenuData]
  event?: MouseEvent;
}

ContextOpenEvent

{
  data: any;
  mouseEvent: MouseEvent;
  preventOpen: () => void;
}

Development

npm start       # run the demo app
npm run build:lib   # build the library

License

MIT © Waqar Naseem