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

[Bug Report] [Component] [input] clearable 会动态改变宽度 #7287

Closed
huang-yf3160 opened this issue Apr 21, 2022 · 24 comments · Fixed by #12897 · May be fixed by #10534
Closed

[Bug Report] [Component] [input] clearable 会动态改变宽度 #7287

huang-yf3160 opened this issue Apr 21, 2022 · 24 comments · Fixed by #12897 · May be fixed by #10534

Comments

@huang-yf3160
Copy link

Bug Type: Component

Environment

  • Vue Version: 3.2.31
  • Element Plus Version: 2.1.10
  • Browser / OS: chrome 99.0.4844.82
  • Build Tool: Vite

Reproduction

Related Component

  • el-input

Reproduction Link

Element Plus Playground

Steps to reproduce

在表单组件下,input组件增加clearable属性,input组件宽度会动态变化

  <el-form inline>
    <el-form-item>
      <el-input v-model="input" placeholder="Please input" clearable />
    </el-form-item>
  </el-form>

What is Expected?

不会变化宽度

What is actually happening?

宽度动态变化

Additional comments

(empty)

@huang-yf3160 huang-yf3160 changed the title [Bug Report] [Component] [input] ElMessageBox confirm button style bug [Bug Report] [Component] [input] ElInput style bug Apr 21, 2022
@josonho
Copy link
Contributor

josonho commented Apr 21, 2022

你好~

因为你的代码中el-input是没有宽度的,
所以实际渲染出来的 el-input宽度 = 原生input宽度 + 前缀图标宽度 + 后缀图标宽度。
可以写css固定el-input宽度来处理。

Element Plus Playground

@huang-yf3160
Copy link
Author

你好~

因为你的代码中el-input是没有宽度的, 所以实际渲染出来的 el-input宽度 = 原生input宽度 + 前缀图标宽度 + 后缀图标宽度。 可以写css固定el-input宽度来处理。

Element Plus Playground

我知道怎么解决,但是在之前的版本里是没有这个问题的。

@sxzz sxzz changed the title [Bug Report] [Component] [input] ElInput style bug [Bug Report] [Component] [input] clearable 会动态改变宽度 Apr 26, 2022
@YunYouJun
Copy link
Member

Maybe it is caused by #7179

Can you have a look?

The solution I can think of is to add a default width to the container, but I'm not sure if this creates additional issues.

@emojiiii
Copy link
Contributor

对于clearable或者可以使用绝对定位去解决,其他继续沿用flex布局 ?

@YunYouJun
Copy link
Member

对于clearable或者可以使用绝对定位去解决,其他继续沿用flex布局 ?

clearable 应该还需要对 suffix 等情况进行判断,以及设置输入框的可显示宽度,可能也比较麻烦。

@plainheart
Copy link
Member

plainheart commented Apr 29, 2022

对于clearable或者可以使用绝对定位去解决

改成绝对定位,就需要动态计算,比较麻烦而且很容易出现问题。之所以改成 flex 布局,就是为了解决开发者指定多个 suffix、prefix 时的布局问题。

clearable 应该还需要对 suffix 等情况进行判断,以及设置输入框的可显示宽度,可能也比较麻烦。

其他组件库默认给了 clearable 占位,但那样默认情况下右侧的留白就会显得比较大,和左侧也不对称,不是很美观。前几天在 discord 讨论过,暂时还想不出好的解决办法。

@YunYouJun
Copy link
Member

为 input container 设置默认宽度是否存在潜在问题?@plainheart

@plainheart
Copy link
Member

@YunYouJun 我觉得还是不要默认设置宽度 个人感觉大多数情况下开发者可能更喜欢默认填充父级宽度 而且加了默认宽度也算是一个小的 BC 了。

@YunYouJun
Copy link
Member

现在的 input 似乎因为浏览器默认 input 会有一个默认宽度,并导致拥有 clearable 等 suffix 元素时改变其宽度。
也许我们应该在文档中提示用户为其容器设置宽度。

cc @JeremyWuuuuu

@tolking
Copy link
Member

tolking commented May 20, 2022

感觉直接可以给一个最小宽度 220px (--el-date-editor-width)?

类似的还有在 el-form inline 中使用 Slider 由于没有最小宽度直接就是一个圆圈。

inline 表单内部相关的组件设置一个最小宽度或许是一个不错的方案

@chenxch
Copy link
Member

chenxch commented Jul 13, 2022

这个问题好像好久没动静了,我看了一遍,也是比较赞同不添加默认宽度,如果没有很好的解决办法,可能要舍弃掉美观这块,采用flex布局。

@tuutoo
Copy link

tuutoo commented Jul 14, 2022

显示隐藏时的宽度可能另一个问题.

可以考虑把这个Hover时显示隐藏Clearable的功能拿掉吗

这功能在视觉上造成了视觉不一致, 主要有下面两种情况

  1. 移动端和桌面端的视觉不一致: 要Hover时显示隐藏这个按钮. 还要考虑移动端的情况, 移动端是没有Hover的.
  2. 多个图标时的视觉不一致: 如果还有其他图标, 比如显示隐藏密码的图标, 又没有做这个Hover和Focus的显示隐藏.

MrWeilian added a commit to MrWeilian/element-plus that referenced this issue Nov 8, 2022
MrWeilian added a commit to MrWeilian/element-plus that referenced this issue Nov 8, 2022
MrWeilian added a commit to MrWeilian/element-plus that referenced this issue Nov 8, 2022
MrWeilian added a commit to MrWeilian/element-plus that referenced this issue Nov 8, 2022
MrWeilian pushed a commit to MrWeilian/element-plus that referenced this issue Nov 8, 2022
In version 2.2.17, use currentPage can't bind variable to current page.

fix(components): [input] input width change by clearable (element-plus#7287)
MrWeilian added a commit to MrWeilian/element-plus that referenced this issue Nov 8, 2022
…s#7287)

fix(components): [input] input width change by clearable (element-plus#7287)

fix(components): [input] input width change by clearable (element-plus#7287)
MrWeilian added a commit to MrWeilian/element-plus that referenced this issue Nov 8, 2022
…s#7287)

fix(components): [input] input width change by clearable (element-plus#7287)

fix(components): [input] input width change by clearable (element-plus#7287)
MrWeilian added a commit to MrWeilian/element-plus that referenced this issue Nov 8, 2022
…s#7287)

fix(components): [input] input width change by clearable (element-plus#7287)

fix(components): [input] input width change by clearable (element-plus#7287)

fix(components): [input] input width change by clearable (element-plus#7287)
MrWeilian added a commit to MrWeilian/element-plus that referenced this issue Nov 8, 2022
…s#7287)

fix(components): [input] input width change by clearable (element-plus#7287)

fix(components): [input] input width change by clearable (element-plus#7287)

fix(components): [input] input width change by clearable (element-plus#7287)
MrWeilian added a commit to MrWeilian/element-plus that referenced this issue Nov 14, 2022
…s#7287)

fix(components): [input] input width change by clearable (element-plus#7287)

fix(components): [input] input width change by clearable (element-plus#7287)

fix(components): [input] input width change by clearable (element-plus#7287)
@agrass-GitHub
Copy link

这个问题太影响使用体验了。无论是定位还是占位感觉都比现在的这个方案合适。

@KYX1234
Copy link

KYX1234 commented Jan 15, 2023

咱就是说,之前饿了么2都没有这个问题的,到3这样用起来真的很不爽,为什么不考虑在form inline模式下给个默认定宽呢

@yezimikk
Copy link

能不能做个input有值的情况下长期显示clearable的图标的API?

@wzc520pyfm
Copy link
Contributor

是否可添加attributes, 让使用者自行决定使用何种方案?
方案一: input宽度随clearable显隐动态调整
方案二: input为clearable预留空间

@tolking
Copy link
Member

tolking commented Apr 23, 2023

为 form inline 模式下的 input 增加默认宽度或许是比较合适的主意

@YunYouJun
Copy link
Member

为 form inline 模式下的 input 增加默认宽度或许是比较合适的主意

Let's do it?

@tolking
Copy link
Member

tolking commented May 17, 2023

为 form inline 模式下的 input 增加默认宽度或许是比较合适的主意

Let's do it?

agree

@dengshenkk
Copy link

还没商量出一个方案吗? 确定下来咔咔先整了再说

@jummyliu
Copy link

注意,给 el-input 指定宽度后 220px (--el-date-editor-width)?,会导致手动指定宽度的 el-select 显示异常 @tolking
image
image

@strangePix
Copy link

strangePix commented Jun 27, 2023

所以路过讨论一下,最后是怎么处理了...全局加默认宽度吗

@YunYouJun
Copy link
Member

所以路过讨论一下,最后是怎么处理了...全局加默认宽度吗

添加默认宽度后,在复用 input 的 select 等多种组件将遇到其他问题,这使得情况更加复杂且难以复用。
反之想要添加固定宽度则更为简单。
考虑到样式的侵入性和可定制性,我们决定仍不添加默认宽度。

并在文档中针对当前问题给出解决方案提示。

#13375

MrWeilian added a commit to MrWeilian/element-plus that referenced this issue Jun 28, 2023
…s#7287)

fix(components): [input] input width change by clearable (element-plus#7287)

fix(components): [input] input width change by clearable (element-plus#7287)

fix(components): [input] input width change by clearable (element-plus#7287)
@GuLinLing
Copy link

GuLinLing commented Dec 22, 2023

不想设置宽度的可以试试,希望官方早点解决
.el-input__suffix:not(.el-select .el-input__suffix) {
margin-left: -22px;
}
.el-input__inner:not(.el-select .el-input__inner) {
padding-right: 22px;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment