Skip to content

Commit

Permalink
actionsheet: Add raw menu data for on-click-menu event (Close #1772)
Browse files Browse the repository at this point in the history
  • Loading branch information
airyland committed Jul 30, 2017
1 parent 7ca6abd commit dc52b76
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/components/actionsheet/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ export default {
methods: {
onMenuClick (text, key) {
if (typeof text === 'string') {
this.emitEvent('on-click-menu', key)
this.emitEvent('on-click-menu', key, text)
} else {
if (text.type !== 'disabled' && text.type !== 'info') {
if (text.value) {
this.emitEvent('on-click-menu', text.value)
this.emitEvent('on-click-menu', text.value, text)
} else {
this.emitEvent('on-click-menu', '', text)
this.show = false
}
}
Expand All @@ -89,9 +90,9 @@ export default {
this.$emit('on-click-mask')
this.closeOnClickingMask && (this.show = false)
},
emitEvent (event, menu) {
emitEvent (event, menu, item) {
if (event === 'on-click-menu' && !/.noop/.test(menu)) {
this.$emit(event, menu)
this.$emit(event, menu, typeof item === 'string' ? item : JSON.parse(JSON.stringify(item)))
this.$emit(`${event}-${menu}`)
this.closeOnClickingMenu && (this.show = false)
}
Expand Down
9 changes: 7 additions & 2 deletions src/components/actionsheet/metas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ props:
zh-CN: 点击菜单时是否自动隐藏
events:
on-click-menu:
params: (menuKey)
params: (menuKey, menuItem)
en: triggers when clicking on the menu
zh-CN: 点击菜单时触发,参数为当前菜单项对象
zh-CN: 点击菜单时触发
on-click-menu-{menuKey}:
params: (menuKey)
en: shortcut event for easier listening, you can listen on `on-click-menu-delete` if you have a menu named `delete`
Expand All @@ -141,6 +141,11 @@ events:
en: triggers when clicking on mask
zh-CN: 点击遮罩时触发
changes:
next:
en:
- '[feature] Add raw menu item for on-click-menu event #1772'
zh-CN:
- '[feature] 支持在 on-click-menu 参数里附带原始 menu 对象 #1772'
v2.3.5:
en:
- '[feature] Support slot:header #1381'
Expand Down
8 changes: 6 additions & 2 deletions src/demos/Actionsheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<actionsheet v-model="show3" :menus="menus3" @on-click-menu="click" @on-click-menu-delete="onDelete" show-cancel></actionsheet>

<actionsheet v-model="show5" :menus="menus5" show-cancel @on-click-menu="click"></actionsheet>
<actionsheet v-model="show5" :menus="menus5" show-cancel @on-click-menu="click5"></actionsheet>

<actionsheet v-model="show6" :menus="menus1">
<p slot="header" v-html="$t('actionsheet header')"></p>
Expand Down Expand Up @@ -116,7 +116,8 @@ export default {
}, {
label: 'Primary',
type: 'primary',
value: 'primary'
value: 'primary',
otherProp: 'hey'
}, {
label: 'Warn',
type: 'warn'
Expand Down Expand Up @@ -158,6 +159,9 @@ export default {
click (key) {
console.log(key)
},
click5 (key, item) {
console.log(key, item)
},
onDelete () {
this.showSuccess = true
}
Expand Down

0 comments on commit dc52b76

Please sign in to comment.