react-component / react-component/input-number
onBlur 里做校验时,无法拿到 format 后的 value 值
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 323
- Forks
- 188
- Avg merge
- 20h 3m
- Merged PRs (30d)
- 1
Description
代码如下:
<InputNumber
precision={0}
onBlur={() => console.log('blur')}
onChange={() => console.log('change')}
/>
当使用 precision 时,如果输入的内容不符合当前精度((比如 0.9),此时失焦,会先触发 onBlur,拿到的 value 值为 0.9。然后 InputNumber 组件再将 value 值格式化,触发 onChange, 此时拿到的 value 值是 1。
在业务中,如果在 onBlur 中去做校验,无法拿到最终格式化后的值。需要通过异步去获取,感觉不是很好,是否能在 onBlur 里将值直接格式化后再出发外层 onBlur 事件?
历史版本有相关 issue 和解决,但是最新版似乎没有。
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the InputNumber example with precision={0}, onBlur, and onChange, then inspect the precision and blur event handling in the repository. Done means the outer onBlur observes the formatted value when blur triggers formatting, with tests covering an input such as 0.9.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100