File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -214,4 +214,41 @@ describe('Radio', () => {
214
214
} ) ;
215
215
expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
216
216
} ) ;
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
+ } ) ;
217
254
} ) ;
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ export default defineComponent({
69
69
if ( ! ( 'checked' in props ) ) {
70
70
this . sChecked = e . target . checked ;
71
71
}
72
+ // fix https://github.com/vueComponent/ant-design-vue/issues/3047
73
+ if ( 'checked' in props ) {
74
+ this . $refs . input . checked = props . checked ;
75
+ }
72
76
this . $forceUpdate ( ) ; // change前,维持现有状态
73
77
e . shiftKey = this . eventShiftKey ;
74
78
const eventObj = {
You can’t perform that action at this time.
0 commit comments