diff --git a/docs/demos/views/actionsheet.vue b/docs/demos/views/actionsheet.vue index 120f103c3..77f47277e 100644 --- a/docs/demos/views/actionsheet.vue +++ b/docs/demos/views/actionsheet.vue @@ -7,7 +7,7 @@ {{ $t('button2') }} - + @@ -61,6 +61,10 @@ export default { methods: { onClick(item) { Toast(item.name); + }, + + handleCancel() { + Toast('cancel'); } } }; diff --git a/docs/markdown/en-US/actionsheet.md b/docs/markdown/en-US/actionsheet.md index 5760d01c6..5654dec23 100644 --- a/docs/markdown/en-US/actionsheet.md +++ b/docs/markdown/en-US/actionsheet.md @@ -72,6 +72,12 @@ Actionsheet will get another style if there is a `title` prop. | close-on-click-overlay | Whether to close when click overlay | `Boolean` | - | - | | get-container | Return the mount node for actionsheet | `Function` | - | `() => HTMLElement` | +### Event + +| Event | Description | Arguments | +|-----------|-----------|-----------| +| cancel | Triggered when cancel click | - | + ### Data struct of actions | key | Description | diff --git a/docs/markdown/zh-CN/actionsheet.md b/docs/markdown/zh-CN/actionsheet.md index 41e6c8f07..d42e3c1c9 100644 --- a/docs/markdown/zh-CN/actionsheet.md +++ b/docs/markdown/zh-CN/actionsheet.md @@ -75,6 +75,12 @@ export default { | close-on-click-overlay | 点击遮罩是否关闭`Actionsheet` | `Boolean` | - | - | | get-container | 指定挂载的 HTML 节点 | `Function` | - | `() => HTMLElement` | +### Event + +| 事件名 | 说明 | 参数 | +|-----------|-----------|-----------| +| cancel | 取消按钮点击时触发 | - | + ### actions `API`中的`actions`为一个对象数组,数组中的每一个对象配置每一列,每一列有以下`key`: diff --git a/packages/actionsheet/index.vue b/packages/actionsheet/index.vue index 57510a86e..4edf14190 100644 --- a/packages/actionsheet/index.vue +++ b/packages/actionsheet/index.vue @@ -3,7 +3,7 @@
- +
  • @@ -65,6 +65,11 @@ export default create({ if (typeof item.callback === 'function') { item.callback(item); } + }, + + handleCancel() { + this.$emit('input', false); + this.$emit('cancel'); } } }); diff --git a/test/specs/actionsheet.spec.js b/test/specs/actionsheet.spec.js index bd6aaf59b..2e5b23a44 100644 --- a/test/specs/actionsheet.spec.js +++ b/test/specs/actionsheet.spec.js @@ -107,6 +107,11 @@ describe('ActionSheet', () => { const cancelButton = wrapper.find('.van-actionsheet__cancel')[0]; expect(wrapper.contains('.van-actionsheet__cancel')).to.be.true; expect(cancelButton.text()).to.equal('cancel'); + + const eventStub = sinon.stub(wrapper.vm, '$emit'); + cancelButton.trigger('click'); + + expect(eventStub.calledWith('cancel')); }); it('toggle actionsheet value from v-model', (done) => {