fix(element): fix Radio.Group's change event is triggered twice, Cause functional failure. #3641 #3665
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before submitting a pull request, please make sure the following is done...
master
orformily_next
.npm test
).npm run lint
) - we've done our best to make sure these rules match our internal linting guidelines.Please do not delete the above content
What have you changed?
修复
ElRadioGroup
组件桥接后的Radio.Group
组件,发生一次点击但触发两次change
事件的现象,进而导致组件点击切换失效的问题。(ElCheckboxGroup
桥接后失效的问题的原因和修复方法可以参考本问题方案)在
@formily/element
的radio
组件中,其桥接ElRadioGroup
的代码逻辑如下:修复结果:
解决方法:
在桥接
ElRadioGroup
组件的时候,屏蔽其 change 事件的干扰即可。具体原因:
首先,在
element-ui
中ElRadio
组件的change
事件,触发其model
的setter
和handleChange
,而model
的setter
会触发ElRadioGroup
组件的input
事件,最后触发Radio.Group
的change
事件,更新Radio.Group
的value
。其次,由于
@formily
的scheduler
是Promise
, 所以handleChange
执行的优先级更高,进而二次触发ElRadioGroup
的change
事件,最后二次触发Radio.Group
的change
事件,更新Radio.Group
的value
。最后,由于
ElRadioGroup
的handleChange
事件获得的值this.model
来源于计算属性,而此时@formily
的scheduler
的reactiveRender
尚未执行。 所以此时ElRadioGroup
组件尚未update
,所以导致handleChange
函数执行时,this.model
获取的值是缓存值,即改变前的旧值(与ElRadioGroup
的input
事件获得的值不一致)。最终导致Radio.Group
的选项切换失败。