fix: checkbox can't trigger change (#3285)

* fix: checkbox can't trigger change

* test: add unit test

* chore: update vc-checkbox
pull/3349/head
zkwolf 2020-12-04 14:01:51 +08:00 committed by GitHub
parent 1581ff3057
commit 8ba75419b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -230,4 +230,41 @@ describe('Radio', () => {
}); });
expect(wrapper.html()).toMatchSnapshot(); expect(wrapper.html()).toMatchSnapshot();
}); });
it('when onChange do not change the value, change event can be also triggered.', async () => {
const onChange = jest.fn();
const onChangeRadioGroup = () => {
onChange();
wrapper.setProps({ value: 'A' });
};
const wrapper = mount(
{
props: ['value'],
render() {
const value = this.value || 'A';
return (
<RadioGroup ref="radioGroup" value={value} onChange={onChangeRadioGroup}>
<Radio value="A">A</Radio>
<Radio value="B">B</Radio>
<Radio value="C">C</Radio>
</RadioGroup>
);
},
},
{ sync: false },
);
const radios = wrapper.findAll('input');
await asyncExpect(() => {
radios.at(1).trigger('click');
expect(onChange.mock.calls.length).toBe(1);
});
await asyncExpect(() => {
radios.at(1).trigger('click');
expect(onChange.mock.calls.length).toBe(2);
});
});
}); });

View File

@ -92,6 +92,10 @@ export default {
nativeEvent: e, nativeEvent: e,
}); });
this.eventShiftKey = false; this.eventShiftKey = false;
// fix https://github.com/vueComponent/ant-design-vue/issues/3047
if ('checked' in props) {
this.$refs.input.checked = props.checked;
}
}, },
onClick(e) { onClick(e) {
this.__emit('click', e); this.__emit('click', e);