fix(Checkbox): get changed value in click event (#6066)

This commit is contained in:
neverland 2020-04-16 16:26:44 +08:00 committed by GitHub
parent 63f789646d
commit 28bbef6b6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -73,7 +73,7 @@ test('checkbox group', async () => {
expect(wrapper.vm.result).toEqual(['b']);
});
test('click event', () => {
test('click event', async () => {
const onClick = jest.fn();
const wrapper = mount(Checkbox, {
listeners: {
@ -82,10 +82,12 @@ test('click event', () => {
});
wrapper.trigger('click');
await later();
expect(onClick).toHaveBeenCalledTimes(1);
const icon = wrapper.find('.van-checkbox__icon');
icon.trigger('click');
await later();
expect(onClick).toHaveBeenCalledTimes(2);
});

View File

@ -69,9 +69,15 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
if (!this.isDisabled && (iconClicked || !this.labelDisabled)) {
this.toggle();
}
this.$emit('click', event);
// wait for toggle method to complete
// so we can get the changed value in the click event listener
setTimeout(() => {
this.$emit('click', event);
});
} else {
this.$emit('click', event);
}
},
genIcon() {