From 7b0a3319ba0d67fd8e209ff6e2cec6790af908c0 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 18 Mar 2019 19:31:23 +0800 Subject: [PATCH] [bugfix] Checkbox: click event untriggered when click icon (#2990) --- packages/checkbox/en-US.md | 1 + packages/checkbox/test/index.spec.js | 16 ++++++++++++++++ packages/checkbox/zh-CN.md | 7 ++++--- packages/mixins/checkbox.js | 5 +++-- packages/radio/en-US.md | 7 ++++++- packages/radio/zh-CN.md | 6 ++++++ 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/checkbox/en-US.md b/packages/checkbox/en-US.md index 39d17c5b6..a01b3be0f 100644 --- a/packages/checkbox/en-US.md +++ b/packages/checkbox/en-US.md @@ -159,6 +159,7 @@ export default { | Event | Description | Parameters | |------|------|------| | change | Triggered when value changed | current value | +| click | Triggered when click checkbox | event: Event | ### CheckboxGroup Event diff --git a/packages/checkbox/test/index.spec.js b/packages/checkbox/test/index.spec.js index 77d5478cd..bb9311ad7 100644 --- a/packages/checkbox/test/index.spec.js +++ b/packages/checkbox/test/index.spec.js @@ -70,3 +70,19 @@ test('checkbox group', () => { icons.at(0).trigger('click'); expect(wrapper.vm.result).toEqual(['b']); }); + +test('click event', () => { + const onClick = jest.fn(); + const wrapper = mount(Checkbox, { + listeners: { + click: onClick + } + }); + + wrapper.trigger('click'); + expect(onClick.mock.calls.length).toEqual(1); + + const icon = wrapper.find('.van-checkbox__icon'); + icon.trigger('click'); + expect(onClick.mock.calls.length).toEqual(2); +}); diff --git a/packages/checkbox/zh-CN.md b/packages/checkbox/zh-CN.md index 0951e9961..16a79e5d2 100644 --- a/packages/checkbox/zh-CN.md +++ b/packages/checkbox/zh-CN.md @@ -144,8 +144,8 @@ export default { | name | 标识符 | `any` | - | - | | shape | 形状,可选值为 `square` | `String` | `round` | - | | v-model | 是否为选中状态 | `Boolean` | `false` | - | -| disabled | 是否禁用单选框 | `Boolean` | `false` | - | -| label-disabled | 是否禁用单选框文本点击 | `Boolean` | `false` | - | +| disabled | 是否禁用复选框 | `Boolean` | `false` | - | +| label-disabled | 是否禁用复选框文本点击 | `Boolean` | `false` | - | | label-position | 文本位置,可选值为 `left` | `String` | `right` | 1.1.11 | | checked-color | 选中状态颜色 | `String` | `#1989fa` | 1.4.3 | @@ -154,7 +154,7 @@ export default { | 参数 | 说明 | 类型 | 默认值 | 版本 | |------|------|------|------|------| | v-model | 所有选中项的标识符 | `Array` | - | - | -| disabled | 是否禁用所有单选框 | `Boolean` | `false` | - | +| disabled | 是否禁用所有复选框 | `Boolean` | `false` | - | | max | 设置最大可选数,0 为无限制 | `Number` | `0` | - | ### Checkbox Event @@ -162,6 +162,7 @@ export default { | 事件名称 | 说明 | 回调参数 | |------|------|------| | change | 当绑定值变化时触发的事件 | 当前组件的值 | +| click | 点击复选框时触发 | event: Event | ### CheckboxGroup Event diff --git a/packages/mixins/checkbox.js b/packages/mixins/checkbox.js index 9df5f55be..d2e136a31 100644 --- a/packages/mixins/checkbox.js +++ b/packages/mixins/checkbox.js @@ -59,8 +59,8 @@ export const CheckboxMixin = (parent, bem) => ({ return (
{ - this.$emit('click'); + onClick={event => { + this.$emit('click', event); }} >
({ onClick={event => { event.stopPropagation(); this.onClickIcon(); + this.$emit('click', event); }} > {CheckIcon} diff --git a/packages/radio/en-US.md b/packages/radio/en-US.md index 1fc7fdf34..1e5b258a2 100644 --- a/packages/radio/en-US.md +++ b/packages/radio/en-US.md @@ -99,7 +99,6 @@ export default { | label-position | Can be set to `left` | `String` | `right` | | checked-color | Checked color | `String` | `#1989fa` | - | - ### RadioGroup API | Attribute | Description | Type | Default | @@ -107,6 +106,12 @@ export default { | v-model | Name of checked radio | `any` | - | | disabled | Diable all radios | `Boolean` | `false` | +### Radio Event + +| Event | Description | Parameters | +|------|------|------| +| click | Triggered when click radio | event: Event | + ### RadioGroup Event | Event | Description | Parameters | diff --git a/packages/radio/zh-CN.md b/packages/radio/zh-CN.md index b5eb84513..ea792275d 100644 --- a/packages/radio/zh-CN.md +++ b/packages/radio/zh-CN.md @@ -110,6 +110,12 @@ export default { | v-model | 当前选中项的标识符 | 任意类型 | - | - | | disabled | 是否禁用所有单选框 | `Boolean` | `false` | - | +### Radio Event + +| 事件名称 | 说明 | 回调参数 | +|------|------|------| +| click | 点击单选框时触发 | event: Event | + ### RadioGroup Event | 事件名称 | 说明 | 回调参数 |