Skip to content

fix: radio cancel change #3517

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

Merged
merged 2 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -87,6 +87,10 @@ export default defineComponent({
this.__emit('update:checked', eventObj);
this.__emit('change', eventObj);
this.eventShiftKey = false;
// fix https://github.com/vueComponent/ant-design-vue/issues/3047
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

放到这行前面吧
this.$forceUpdate(); // change前,维持现有状态

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if ('checked' in props) {
this.$refs.input.checked = props.checked;
}
},
onClick(e) {
this.__emit('click', e);
Expand Down