Uh oh!
There was an error while loading. Please reload this page.
fix: trigger onChange twice when inputting using the input method - #60
fix: trigger onChange twice when inputting using the input method#60Adrian-Zephyr-Liao wants to merge 4 commits into
Conversation
Adrian-Zephyr-Liao
commented
Dec 25, 2023
Uh oh!
There was an error while loading. Please reload this page.
yoyo837
commented
Dec 25, 2023
需要添加测试用例 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@## master #60 +/- ##
==========================================
+ Coverage 97.31% 97.40% +0.09%
==========================================
Files 5 5 Lines 186 193 +7 Branches 68 69 +1 ==========================================
+ Hits 181 188 +7
Misses 5 5 ☔ View full report in Codecov by Sentry. |
Adrian-Zephyr-Liao
commented
Dec 25, 2023
已添加测试用例,主要有两点:
|
| cutValue = countConfig.exceedFormatter(currentValue, { | ||
| max: countConfig.max, | ||
| if (isExceed(currentValue)) { | ||
| cutValue = countConfig.exceedFormatter!(currentValue, { |
There was a problem hiding this comment.
我目前能想到的还有一个思路是:
将formatter相关的代码抽离出来,返回一个cutValue和isExceedconst { cutValue, isExceed } = onInternalFormatter(e.currentTarget.value);
在onInternalChange的事件中,formatter后直接触发triggerChange
在onInternalCompositionEnd的事件中,判断是否isExceed,如果为true就触发triggerChange
There was a problem hiding this comment.
我认为fomatter是一个独立的事情,isExceed和cutValue都是和formatter相关的内容,表示格式化后是否超出限制和最终裁剪的值。目前的处境是在change的时候需要格式化,在compositionEnd的时候需要格式化并且条件调用change
| }); | ||
| if (currentValue !== cutValue) { | ||
| setSelection([ |
yoyo837
commented
Dec 27, 2023
#61 你觉得怎样? |
Adrian-Zephyr-Liao
commented
Dec 27, 2023
emmm,其实我一开始也想在triggerChange上加参数,这确实是最简单的改法。但往triggerChange这种语义化的函数中堆除了e和value之外的参数总感觉怪怪的😂如果后续再来个类似的需求,又得加参数了。 |
Adrian-Zephyr-Liao
commented
Dec 27, 2023
纯函数有些时候也不一定能保证,无非是把set值的操作再放到另外一个函数中去 |

The onCompositionEnd event will be called when the user input method combination ends, triggering an onChange event, but it only needs to be called after the count method of Input is successfully cropped.
fixant-design/ant-design#46587
close#61