• Stars
    star
    220
  • Rank 180,422 (Top 4 %)
  • Language Vue
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📌 Simple context-menu component built for Vue. Works well with both left and right clicks. Nothing too fancy, just works and is simple to use.

vue-simple-context-menu

Simple context-menu component built for Vue. Works well with both left and right clicks. Nothing too fancy, just works and is simple to use.

NPM Version NPM Downloads License Tweet

Vue 3 Support

Vue 3 is supported from v4.0.0 and beyond (current master). To use vue-simple-context-menu with Vue 2, use v3.4.2.

Install

yarn add vue-simple-context-menu

About

Just a simple little menu to be shown where a click happens - closes after use automatically by clicking an option or outside of the menu. Multiple menus are supported - just make sure to use a unique string as your element-id prop value.

A nice feature that comes baked in is the menu placement after a click - it sits just ever so slightly under your click location - so that any hover style you had on the item that was clicked gets removed nicely. I modeled it after the macOS right click menu.

Usage

import { createApp } from 'vue';
import VueSimpleContextMenu from 'vue-simple-context-menu';
import 'vue-simple-context-menu/dist/vue-simple-context-menu.css';

const app = createApp(App);

app.component('vue-simple-context-menu', VueSimpleContextMenu);
<!-- This is a basic use case where you have an array of items that you want
to allow to be clicked. In this case, `items` is an array of objects.
Each item has a click event that ties to a function. See the demo for a full example (with multiple menus as well). -->
<div class="item-wrapper">
  <div
    v-for="item in items"
    @click.prevent.stop="handleClick($event, item)"
    class="item-wrapper__item"
  >
    {{item.name}}
  </div>
</div>

<!-- Make sure you add the `ref` attribute, as that is what gives you the ability
to open the menu. -->
<vue-simple-context-menu
  element-id="myUniqueId"
  :options="options"
  ref="vueSimpleContextMenu"
  @option-clicked="optionClicked"
/>
handleClick (event, item) {
  this.$refs.vueSimpleContextMenu.showMenu(event, item)
}


optionClicked (event) {
  window.alert(JSON.stringify(event))
}

Note - you must pass the click event-info variable to the showMenu() function because that's how we know where to show the menu.

Note - make sure to use @click.prevent.stop (or @contextmenu.prevent.stop for right click) when setting up the click handler.

Props

prop type description required
elementId String Unique String that acts as the id of your menu. Yes
options Array Array of menu options to show. Component will use the name parameter as the label. Yes
options.name String Label for the option. Yes
options.class String A custom class that will be applied to the option. No
options.type String Only one possible value at the moment - divider. Pass this to set the object as a divider. No
ref String Unique String that allows you to show the menu on command. Yes

Methods

method parameters description
showMenu event (MouseEvent), item (Object) Used to show the menu. Make sure to pass a MouseEvent and an Object.

Events

event value description
option-clicked Object When a menu item is clicked the component will emit an event with a value containing the clicked item and the menu option that was clicked. Register for this event to capture the selection result.
menu-closed Emitted when the menu is closed

SASS Structure

.vue-simple-context-menu {
  &--active {
  }

  &__item {
    &:hover {
    }
  }

  &__divider {
  }
}

Development

# Install dependencies
yarn

# Serve with hot reload
yarn dev

# Run the tests
yarn test

# Build demo page
yarn build:example

# Build library
yarn build:library

# Build everything and run tests
yarn build

Other

Go ahead and fork the project! Submit an issue if needed. Have fun!

Thank You

Influenced by Lucas Calazans's pen. Go ahead and check out his other work.

License

MIT

More Repositories

1

file-upload-with-preview

🖼 Simple file-upload utility that shows a preview of the uploaded image. Written in TypeScript. No dependencies. Works well with or without a framework.
TypeScript
447
star
2

koa-vue-notes-api

🤓 This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Features MySQL integration, user authentication, CRUD note actions, and async/await.
JavaScript
366
star
3

koa-vue-notes-web

🤓 This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Features MySQL integration, user authentication, CRUD note actions, and Vuex store modules.
SCSS
199
star
4

vue-navigation-bar

🧭 A simple, pretty navbar for your Vue projects.
Vue
165
star
5

vue-cookie-accept-decline

👋 Show a banner with text, a decline button, and an accept button on your page. Remembers selection using cookies. Emits an event with current selection and on creation. Good for GDPR requirements.
Vue
137
star
6

koa-react-notes-web

🤓 This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Features MySQL integration, user authentication, CRUD note actions, and more.
TypeScript
68
star
7

vue-screen-size

🖥 Get easy and reactive access to the width and height of your screen.
Vue
43
star
8

modern-webpack-starter

🏰 A modern JavaScript starter using Webpack 4. Made in a simple way - good for learning or starting a new project without having to rollout cli-auto-builders.
JavaScript
41
star
9

vue-video-section

📼 A simple video header/section component for Vue. Good for video backgrounds and overlaying content on them.
Vue
32
star
10

vue-programmatic-invisible-google-recaptcha

🔒A simple invisible Google reCAPTCHA component focused solely on programmatic invocation.
Vue
27
star
11

vue-countable

✍️ Vue binding for countable.js. Provides real-time paragraph, sentence, word, and character counting.
Vue
25
star
12

koa-vue-notes-project

🤓 A single repo containing both the koa-vue-notes-api and koa-vue-notes-web projects.
JavaScript
14
star
13

chrome-ribbon-reminder

🎀 A Chrome extension written using Vue and Async/Await. Uses a popup display and changes badge counts.
Vue
12
star
14

vue-mock-layout

💻 Easily mock the layout of your Vue apps.
Vue
7
star
15

vue-mailchimp-email-signup-form

📮 Easily collect email signups using MailChimp in your Vue projects.
JavaScript
4
star
16

react-mailchimp-email-signup-form

📮 Easily collect email signups using MailChimp in your React projects.
TypeScript
3
star
17

find-the-state-ui

🔍 Find all the States in the contiguous USA on a map. Simple enough.
TypeScript
1
star
18

find-the-state-api

🔍 Find all the States in the contiguous USA on a map. Simple enough.
Python
1
star
19

RecordPlayer

🎻 Emulate a record player in Sprite Kit using Swift and Xcode.
Swift
1
star