-
Notifications
You must be signed in to change notification settings - Fork 463
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
input-number值在改变的时候赋值存在异常情况 #2900
Comments
👋 @JobinJia,感谢给 TDesign 提出了 issue。 |
数值为空,应当保持为 上述期望的第 2 点 以及 问题第 2 点,已于 2023-06-07 发布的 |
我其实不太明白,为什么会期望空值是 `null`,明明 null 的类型是 object。 在某一天,某一处的代码要进行类型判断的时候,不会有坑么? undefined 代表不存在或者未定义,input-number 空值应该用 null(数字的清空本应该是 0,但 0 有意义,故而用 null 代替,如果是 text input,清空就直接用 '' 了,都无法清空回 undefined)。而 typeof null 这个属于 JS 语言的 “feature”,开发者本就不能用 typeof 判断 null,此类问题诸如 typeof []、typeof NaN 等都不那么符合直觉,也是开发者自身需要注意的,组件库内部应当以尽可能合理且规范的形式进行实现。undefined 与 null 的差异及各自的使用场景可以在网上参考诸多文章,ant design input-number空值也是给的 null(参见:https://github.com/ant-design/ant-design/issues/13896,里面还提到了放在表单里的情况,undefined 会被过滤掉导致无法传到服务端) |
重现链接
https://stackblitz.com/edit/vitejs-vite-2vjngr?file=src%2Fmain.ts,src%2FApp.vue
重现步骤
1: 删除值,在为空值的时候 model中的key丢失。失焦时,model.num的值变为"" 空串
2: 输入
1eee
之后删除一个字符e. 此时model.num的值变为null, 视图变成NaN,无法再通过删除键删除期望结果
1:删除值为空时为null, 失焦为null
2: 删除非数值字符时不触发v-model的改变(在只考虑10进制,不考虑其它进制的情况下)
实际结果
见重现链接
The text was updated successfully, but these errors were encountered: