mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[bugfix] Checkbox: should not prevent click event
This commit is contained in:
parent
6d0b5e5a0d
commit
ecadb5d1e7
@ -30,7 +30,15 @@ export default sfc({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
toggle() {
|
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() {
|
onClickIcon() {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import Checkbox from '..';
|
import Checkbox from '..';
|
||||||
import CheckboxGroup from '../../checkbox-group';
|
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);
|
const wrapper = mount(Checkbox);
|
||||||
|
|
||||||
wrapper.vm.$on('input', value => {
|
wrapper.vm.$on('input', value => {
|
||||||
@ -11,8 +11,9 @@ test('switch checkbox', () => {
|
|||||||
|
|
||||||
const icon = wrapper.find('.van-checkbox__icon');
|
const icon = wrapper.find('.van-checkbox__icon');
|
||||||
icon.trigger('click');
|
icon.trigger('click');
|
||||||
|
await later();
|
||||||
icon.trigger('click');
|
icon.trigger('click');
|
||||||
|
await later();
|
||||||
expect(wrapper.emitted('input')).toEqual([[true], [false]]);
|
expect(wrapper.emitted('input')).toEqual([[true], [false]]);
|
||||||
expect(wrapper.emitted('change')).toEqual([[true], [false]]);
|
expect(wrapper.emitted('change')).toEqual([[true], [false]]);
|
||||||
});
|
});
|
||||||
@ -42,7 +43,7 @@ test('label disabled', () => {
|
|||||||
expect(wrapper.emitted('input')).toBeFalsy();
|
expect(wrapper.emitted('input')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('checkbox group', () => {
|
test('checkbox group', async () => {
|
||||||
const wrapper = mount({
|
const wrapper = mount({
|
||||||
template: `
|
template: `
|
||||||
<checkbox-group v-model="result" :max="2">
|
<checkbox-group v-model="result" :max="2">
|
||||||
@ -63,11 +64,15 @@ test('checkbox group', () => {
|
|||||||
|
|
||||||
const icons = wrapper.findAll('.van-checkbox__icon');
|
const icons = wrapper.findAll('.van-checkbox__icon');
|
||||||
icons.at(0).trigger('click');
|
icons.at(0).trigger('click');
|
||||||
|
await later();
|
||||||
icons.at(1).trigger('click');
|
icons.at(1).trigger('click');
|
||||||
|
await later();
|
||||||
icons.at(2).trigger('click');
|
icons.at(2).trigger('click');
|
||||||
expect(wrapper.vm.result).toEqual(['a', 'b']);
|
expect(wrapper.vm.result).toEqual(['a', 'b']);
|
||||||
|
|
||||||
|
await later();
|
||||||
icons.at(0).trigger('click');
|
icons.at(0).trigger('click');
|
||||||
|
await later();
|
||||||
expect(wrapper.vm.result).toEqual(['b']);
|
expect(wrapper.vm.result).toEqual(['b']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ export const CheckboxMixin = (parent, bem) => ({
|
|||||||
<div
|
<div
|
||||||
class={bem()}
|
class={bem()}
|
||||||
onClick={event => {
|
onClick={event => {
|
||||||
event.stopPropagation();
|
|
||||||
this.$emit('click', event);
|
this.$emit('click', event);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user