fix: radio cancel change (#3517)
* fix: radio cancel change #3047 * chore: update checkboxpull/3538/head
parent
a6c3eae304
commit
2904ceeab9
|
@ -214,4 +214,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[1].trigger('click');
|
||||||
|
expect(onChange.mock.calls.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
await asyncExpect(() => {
|
||||||
|
radios[1].trigger('click');
|
||||||
|
expect(onChange.mock.calls.length).toBe(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -69,6 +69,10 @@ export default defineComponent({
|
||||||
if (!('checked' in props)) {
|
if (!('checked' in props)) {
|
||||||
this.sChecked = e.target.checked;
|
this.sChecked = e.target.checked;
|
||||||
}
|
}
|
||||||
|
// fix https://github.com/vueComponent/ant-design-vue/issues/3047
|
||||||
|
if ('checked' in props) {
|
||||||
|
this.$refs.input.checked = props.checked;
|
||||||
|
}
|
||||||
this.$forceUpdate(); // change前,维持现有状态
|
this.$forceUpdate(); // change前,维持现有状态
|
||||||
e.shiftKey = this.eventShiftKey;
|
e.shiftKey = this.eventShiftKey;
|
||||||
const eventObj = {
|
const eventObj = {
|
||||||
|
|
Loading…
Reference in New Issue