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

[Component] [input-number] input-number cant set valueOnClear at first-time when v-model was undefined #16726

Closed
xxholly32 opened this issue Apr 30, 2024 · 2 comments

Comments

@xxholly32
Copy link
Sponsor Contributor

xxholly32 commented Apr 30, 2024

Bug Type: Component

Environment

  • Vue Version: 3.4.19
  • Element Plus Version: 2.7.2
  • Browser / OS: UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
  • Build Tool: Vite

Reproduction

Related Component

  • el-input-number

Reproduction Link

Element Plus Playground

Steps to reproduce

输入数字后删除
Enter a number and delete it

What is Expected?

期望也可以切换到 valueOnClear
want set valueOnClear

What is actually happening?

没有设置 valueOnClear
valueOnClear not set at first time

Additional comments

我稍微思考了下,有2个方案

I've given it some thought, and there are two options

  1. 合并这里的代码 https://github.com/element-plus/element-plus/blob/dev/packages/components/input-number/src/input-number.vue#L214

  2. Merge the code here https://github.com/element-plus/element-plus/blob/dev/packages/components/input-number/src/input-number.vue#L214

if (value === '' || isNil(value) || Number.isNaN(newVal)) {
    if (valueOnClear === null) {
      return null
    }
    newVal = isString(valueOnClear) ? { min, max }[valueOnClear]!! : valueOnClear
  }

这样会有个问题是 valueOnClear 会默认展示,但改动是比较小的

One problem with this is that valueOnClear displays by default, but the changes are minor

  1. 还有一个方案的话是参考 el-input,因为 el-input,的v-model的default 是 '' 而el-input-number 是undefined 改成 '',所以这块对于里面底层的改动会比较大,要去掉一些不必要null和 undefined的判断

个人比较倾向于第二种

  1. There is also a solution that refers to input, because the default of the v-model of el-input is "" and the el-input-number is undefined, changed to" ", so this will change the bottom of the inside will be relatively large, To remove some unnecessary null and undefined judgment

Personally, I prefer the second option

@makedopamine
Copy link
Contributor

I think the feature you requested out of the semantics of valueOnClear. What you actually want is something like defaultValue which sets a default value when the value is undefined or null. But I don't see the need for it, and just set the initial value same as valueOnClear.

@xxholly32
Copy link
Sponsor Contributor Author

You're right. I'm stuck in my own mindset

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

No branches or pull requests

2 participants