Skip to content

Commit

Permalink
feat: 添加 disabled 属性 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
Snokier committed Jun 2, 2018
1 parent fe40fe3 commit 489e29f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/usage-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Base Contextmenu Component
| ---------- | ------------- | ------ | ---------- | ------------- |
| eventType | event to bind | String | any events | contextmenu |
| theme | theme | String | default / bright | default |
| disabled | disable the Menu (will not appear) | Boolean | true / false | false |
| autoPlacement | whether change placement automatically when the Menu is outside of Window | Boolean | true / false | true |

**Methods**
Expand Down
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
| ---------- | ----------------- | ------ | ----- | ---------- |
| eventType | 触发其显示的事件类型 | String | 事件名 | contextmenu |
| theme | 主题 | String | default / bright | default |
| disabled | 是否禁用菜单(菜单不会出现) | Boolean | true / false | false |
| autoPlacement | 是否自动切换方位,即当菜单显示时溢出浏览器窗口可视区域,自动切换显示方位 | Boolean | true / false | true |

**Methods**
Expand Down
15 changes: 12 additions & 3 deletions examples/Disabled.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="example">
<v-contextmenu ref="contextmenu" :theme="theme">
<v-contextmenu ref="contextmenu" :theme="theme" :disabled="disabled">
<v-contextmenu-item @click="handleClick">菜单1</v-contextmenu-item>
<v-contextmenu-item disabled @click="handleClick">菜单2</v-contextmenu-item>

Expand All @@ -19,8 +19,8 @@
</v-contextmenu-submenu>
</v-contextmenu>

<div :class="['box', theme]" v-contextmenu:contextmenu>
右键点击此区域
<div :class="['box', theme]" v-contextmenu:contextmenu @click="handleSwitchDisabled">
左键点击切换禁用状态,右键点击打开菜单
</div>
</div>
</template>
Expand All @@ -33,10 +33,19 @@
theme: String,
},
data () {
return {
disabled: false,
}
},
methods: {
handleClick (vm, event) {
console.log(vm, event)
},
handleSwitchDisabled () {
this.disabled = !this.disabled
},
},
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "v-contextmenu",
"description": "ContextMenu based on Vue 2.0",
"version": "2.6.0",
"version": "2.7.0",
"author": "snokier <me@snokier.com>",
"main": "dist/index.common.js",
"files": [
Expand Down
3 changes: 3 additions & 0 deletions src/components/Contextmenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
type: Boolean,
default: true,
},
disabled: Boolean,
},
data () {
Expand Down Expand Up @@ -102,6 +103,8 @@
handleReferenceContextmenu (event) {
event.preventDefault()
if (this.disabled) return
const reference = this.references.find(ref => ref.el.contains(event.target))
this.$emit('contextmenu', reference ? reference.vnode : null)
Expand Down

0 comments on commit 489e29f

Please sign in to comment.