mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Checkbox): get changed value in click event (#6066)
This commit is contained in:
parent
63f789646d
commit
28bbef6b6f
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user