Skip to content

Commit d4ecdd5

Browse files
committed
fix: radio cancel change vueComponent#3047
1 parent 3650229 commit d4ecdd5

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

components/radio/__tests__/group.test.js

+37
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,41 @@ describe('Radio', () => {
214214
});
215215
expect(wrapper.html()).toMatchSnapshot();
216216
});
217+
218+
it('when onChange do not change the value, change event can be also triggered.', async () => {
219+
const onChange = jest.fn();
220+
const onChangeRadioGroup = () => {
221+
onChange();
222+
wrapper.setProps({ value: 'A' });
223+
};
224+
225+
const wrapper = mount(
226+
{
227+
props: ['value'],
228+
render() {
229+
const value = this.value || 'A';
230+
return (
231+
<RadioGroup ref="radioGroup" value={value} onChange={onChangeRadioGroup}>
232+
<Radio value="A">A</Radio>
233+
<Radio value="B">B</Radio>
234+
<Radio value="C">C</Radio>
235+
</RadioGroup>
236+
);
237+
},
238+
},
239+
{ sync: false },
240+
);
241+
242+
const radios = wrapper.findAll('input');
243+
244+
await asyncExpect(() => {
245+
radios[1].trigger('click');
246+
expect(onChange.mock.calls.length).toBe(1);
247+
});
248+
249+
await asyncExpect(() => {
250+
radios[1].trigger('click');
251+
expect(onChange.mock.calls.length).toBe(2);
252+
});
253+
});
217254
});

components/vc-checkbox/src/Checkbox.jsx

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ export default defineComponent({
8787
this.__emit('update:checked', eventObj);
8888
this.__emit('change', eventObj);
8989
this.eventShiftKey = false;
90+
// fix https://github.com/vueComponent/ant-design-vue/issues/3047
91+
if ('checked' in props) {
92+
this.$refs.input.checked = props.checked;
93+
}
9094
},
9195
onClick(e) {
9296
this.__emit('click', e);

0 commit comments

Comments
 (0)