diff --git a/docs/markdown/en-US/checkbox.md b/docs/markdown/en-US/checkbox.md index 39c6c67ea..572f8c973 100644 --- a/docs/markdown/en-US/checkbox.md +++ b/docs/markdown/en-US/checkbox.md @@ -90,6 +90,7 @@ export default { |-----------|-----------|-----------|-------------|-------------| | name | Checkbox name | `Boolean` | `false` | - | | disabled | Diable checkbox | `Boolean` | `false` | - | +| label-disabled | Whether to disable label click | `Boolean` | `false` | - | | shape | Checkbox shape | `String` | `round` | `square` | ### CheckboxGroup API diff --git a/packages/checkbox/index.vue b/packages/checkbox/index.vue index 54cebf158..08154cd18 100644 --- a/packages/checkbox/index.vue +++ b/packages/checkbox/index.vue @@ -100,8 +100,8 @@ export default create({ }, methods: { - onClick(flag) { - if (!this.isDisabled && (flag !== 'label' || (flag === 'label' && !this.labelDisabled))) { + onClick(target) { + if (!this.isDisabled && !(target === 'label' && this.labelDisabled)) { this.currentValue = !this.currentValue; } } diff --git a/test/specs/checkbox.spec.js b/test/specs/checkbox.spec.js index 5de1b8a61..35c86e42e 100644 --- a/test/specs/checkbox.spec.js +++ b/test/specs/checkbox.spec.js @@ -194,4 +194,21 @@ describe('Checkbox', () => { expect(wrapper.vm.currentValue).to.be.false; }); + + it('click on a disabled checkbox label', () => { + wrapper = mount(Checkbox, { + propsData: { + value: false, + labelDisabled: true + } + }); + + expect(wrapper.hasClass('van-checkbox')).to.be.true; + expect(wrapper.vm.currentValue).to.be.false; + + const checkboxLabel = wrapper.find('.van-checkbox__label')[0]; + checkboxLabel.trigger('click'); + + expect(wrapper.vm.currentValue).to.be.false; + }); });