Skip to content
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

Closed
JobinJia opened this issue May 26, 2023 · 5 comments · Fixed by #3098
Closed

input-number值在改变的时候赋值存在异常情况 #2900

JobinJia opened this issue May 26, 2023 · 5 comments · Fixed by #3098

Comments

@JobinJia
Copy link

重现链接

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进制,不考虑其它进制的情况下)

实际结果

见重现链接

Environment Info
相关版本 1.3.4
框架版本 / 基础库版本 Vue(3.3.4)
系统、浏览器 Chrome 113.0.5672.127(正式版本) (64 位)
Node版本
@github-actions
Copy link
Contributor

👋 @JobinJia,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@RSS1102
Copy link
Contributor

RSS1102 commented May 26, 2023

InputNumber的输入框为空时,被修改为了undefined
image

@chaishi
Copy link
Collaborator

chaishi commented Jul 19, 2023

数值为空,应当保持为 undefined,而非 null

上述期望的第 2 点 以及 问题第 2 点,已于 2023-06-07 发布的 v1.3.6 版本修复。

@chaishi
Copy link
Collaborator

chaishi commented Jul 19, 2023

image

我其实不太明白,为什么会期望空值是 null,明明 null 的类型是 object。
在某一天,某一处的代码要进行类型判断的时候,不会有坑么?

@xixileng
Copy link
Contributor

xixileng commented Jul 20, 2023

image 我其实不太明白,为什么会期望空值是 `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 会被过滤掉导致无法传到服务端)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants