Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: radio cancel change #3517

Merged
merged 2 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions components/radio/__tests__/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,41 @@ describe('Radio', () => {
});
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);
});
});
});
4 changes: 4 additions & 0 deletions components/vc-checkbox/src/Checkbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export default defineComponent({
if (!('checked' in props)) {
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前,维持现有状态
e.shiftKey = this.eventShiftKey;
const eventObj = {
Expand Down