Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mturco/context-menu

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mturco/context-menu

A small JavaScript library for adding context menus to any HTML element

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

context-menu

A small (4.4kb / 1.7kb gzipped) JavaScript library for adding context menus to any HTML element.

npm install @mturco/context-menu

See demo

API

Constructor

new ContextMenu(selector, items[, options]);
  • selector (String) - Show context menus for elements matching this selector
  • items (Array) - Array of menu items objects in the format of:
    • name (String) - Label displayed for menu item
    • fn (Function) - onclick event handler for menu item
    • Note: to insert a divider, insert an empty object ({}) in the items array.
  • options (Object)
    • className (String, default: '') - CSS class to add to the context menu element
    • minimalStyling (Boolean, default: false) - If true, does not apply default theme CSS class to context menu element

.on() / .off()

ContextMenu.prototype.on(type, listener);
ContextMenu.prototype.off(type, listener);
  • type (String) - Event type; one of: created, shown, hidden, itemselected
  • listener (Function) - Callback for event listener

.destroy()

Removes DOM elements and event listeners.

Example

import ContextMenu from 'context-menu';

const menu = new ContextMenu('table tr', [
  {
    name: 'Add row',
    fn: () => {
      /* ... */
    },
  },
  {
    name: 'Remove row',
    fn: () => {
      /* ... */
    },
  },
]);

menu.on('itemselected', () => {
  /* ... */
});

FAQs

Package last updated on 20 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc