diff --git a/packages/checkbox/index.js b/packages/checkbox/index.js index e01f188cf..8c89c2686 100644 --- a/packages/checkbox/index.js +++ b/packages/checkbox/index.js @@ -30,7 +30,15 @@ export default sfc({ methods: { toggle() { - this.checked = !this.checked; + const checked = !this.checked; + + // When toggle method is called multiple times at the same time, + // only the last call is valid. + // This is a hack for usage inside Cell. + clearTimeout(this.toggleTask); + this.toggleTask = setTimeout(() => { + this.checked = checked; + }); }, onClickIcon() { diff --git a/packages/checkbox/test/index.spec.js b/packages/checkbox/test/index.spec.js index 5c2572b60..5920d5899 100644 --- a/packages/checkbox/test/index.spec.js +++ b/packages/checkbox/test/index.spec.js @@ -1,8 +1,8 @@ import Checkbox from '..'; import CheckboxGroup from '../../checkbox-group'; -import { mount } from '../../../test/utils'; +import { mount, later } from '../../../test/utils'; -test('switch checkbox', () => { +test('switch checkbox', async () => { const wrapper = mount(Checkbox); wrapper.vm.$on('input', value => { @@ -11,8 +11,9 @@ test('switch checkbox', () => { const icon = wrapper.find('.van-checkbox__icon'); icon.trigger('click'); + await later(); icon.trigger('click'); - + await later(); expect(wrapper.emitted('input')).toEqual([[true], [false]]); expect(wrapper.emitted('change')).toEqual([[true], [false]]); }); @@ -42,7 +43,7 @@ test('label disabled', () => { expect(wrapper.emitted('input')).toBeFalsy(); }); -test('checkbox group', () => { +test('checkbox group', async () => { const wrapper = mount({ template: ` @@ -63,11 +64,15 @@ test('checkbox group', () => { const icons = wrapper.findAll('.van-checkbox__icon'); icons.at(0).trigger('click'); + await later(); icons.at(1).trigger('click'); + await later(); icons.at(2).trigger('click'); expect(wrapper.vm.result).toEqual(['a', 'b']); + await later(); icons.at(0).trigger('click'); + await later(); expect(wrapper.vm.result).toEqual(['b']); }); diff --git a/packages/mixins/checkbox.js b/packages/mixins/checkbox.js index 6d8ea11a6..6f369d09e 100644 --- a/packages/mixins/checkbox.js +++ b/packages/mixins/checkbox.js @@ -60,7 +60,6 @@ export const CheckboxMixin = (parent, bem) => ({
{ - event.stopPropagation(); this.$emit('click', event); }} >