
Security News
CISA Kills Off RSS Feeds for KEVs and Cyber Alerts
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
vanilla-context-menu-point
Advanced tools
Easily create context menus using vanilla JavaScript and integrate them in any web application
vanilla-context-menu
- easily create context-menus using Vanilla JavaScript and integrate them in any web application
<script src="https://unpkg.com/vanilla-context-menu@1.0.0/dist/vanilla-context-menu.js"></script>
Where @1.0.0
is the version that you want to use.
Then anywhere in your JavaScript code you can access the library with window.VanillaContextMenu
or simply VanillaContextMenu
.
npm i vanilla-context-menu
Then anywhere in your code.
import VanillaContextMenu from 'vanilla-context-menu';
new VanillaContextMenu({
scope: document.querySelector('main'),
menuItems: [
{
label: 'Copy',
callback: () => {
// ? your code here
},
},
'hr',
{
label: 'Paste',
callback: pasteFunction,
},
],
});
VanillaContextMenu(configurableOptions: ConfigurableOptions):VanillaContextMenu
ConfigurableOptions
Option | Required | Type | Default | Description |
---|---|---|---|---|
scope | yes | HTMLElement | undefined | The HTML element on which you want to bind the contextmenu event listener. |
menuItems | yes | MenuItem[] | undefined | Menu items to be built. |
customClass | no | string | undefined | A custom CSS class that can be added to the context menu |
customThemeClass | no | string | undefined | A custom CSS class that can be added to the context menu theme. A value for this property will exclude the theme option. |
preventCloseOnClick | no | boolean | false | If this variable is true , then the context menu will not close when its elements are clicked. |
transitionDuration | no | number | 200 | Duration of the context menu transition. Set this value to 0 if you want to disable the animation. |
theme | no | 'black' | 'white' | black | By default, the library provides two themes for the context menu: black and white . You can use this option to choose the one you want to use. |
MenuItem
type MenuItem = MenuOption | 'hr';
MenuOption
Option | Required | Type | Default | Description |
---|---|---|---|---|
label | yes | string | undefined | Menu option label. |
callback | yes | () => any | undefined | Callback to be executed. |
preventCloseOnClick | no | boolean | false | If this variable is true , then the context menu will not close when this menu option is clicked. A value set for this option, either true or false will override the global one. |
The following methods and properties are available through the class instance.
const myContextMenu = new VanillaContextMenu(...)
(1)
off(): void
This method will remove all event listeners that have been registered for the context-menu.
! It should be called when you want to deactivate the context menu or when the container item has been removed from the DOM.
(2)
updateOptions(configurableOptions: Partial<ConfigurableOptions>): void
.context-menu-orange-theme {
background: #d35400;
hr {
background-color: #eee;
}
// ? text color for each item
& > *:not(hr) {
color: #eee;
&:hover {
background: #e67e22;
}
}
}
.custom-context-menu-cls {
width: 150px;
font-family: 'Roboto', sans-serif; /* DEFAULT -- font-family: 'Open Sans', sans-serif; */
}
const myContextMenu = new window.VanillaContextMenu({
scope: ...,
menuItems: [...],
customThemeClass: 'context-menu-orange-theme',
customClass: 'custom-context-menu-cls',
});
You can check the demo
file for more examples from demo/index.html.
Pull requests and stars are always welcome. Please check the guidelines.
This project is licensed under the MIT License
FAQs
Did you know?
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.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.