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

antd Select组件 Option里的值前后有空格则会出现崩溃现象,希望官方可以加入去除空格的操作 #28163

Closed
1 task
521guyu opened this issue Dec 3, 2020 · 3 comments
Labels
🤔 Need Reproduce We cannot reproduce your problem

Comments

@521guyu
Copy link

521guyu commented Dec 3, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

默认option.props.children的类型是string,使用indexOf,toLowerCase字符串的方法都没问题。但是一旦Option标签里显示值的前后有空格则option.props.children的类型则会成为array类型。这时如果使用了string的方法则会报错导致页面崩溃。
例如:
const name="maz"; <Otion> {name} </Option> //<Otion>{name}</Option>这样就没问题
这时option.props.children就会变为数组类型['','maz',''];
最小可复现代码
https://codesandbox.io/s/enqcp?file=/index.js

What does the proposed API look like?

正则自动匹配当前筛选项是否包含空格自动去除。考虑到有的需求需要保留空格,可以给filterOption加一个属性是否去除空格。

@afc163 afc163 added the 🤔 Need Reproduce We cannot reproduce your problem label Dec 3, 2020
@ant-design-bot
Copy link
Contributor

Hello @521guyu. Please provide a online reproduction by forking this link https://u.ant.design/codesandbox-repro or a minimal GitHub repository. Issues labeled by Need Reproduce will be closed if no activities in 7 days.

你好 @521guyu, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击 此处 创建一个 codesandbox 或者提供一个最小化的 GitHub 仓库。7 天内未跟进的 issue 将会被自动关闭。

@521guyu
Copy link
Author

521guyu commented Dec 3, 2020

你好@ 521guyu。请通过分叉此链接https://u.ant.design/codesandbox-repro或最小的GitHub存储库来提供在线复制。`Need Reproduce`如果在7天内没有任何活动,则带有标记的问题将被关闭。

你好@ 521guyu,我们需要你提供一个在线的重现实例煞于我们帮你排查问题。你可以通过单击此处创建一个codeandbox或提供一个最小化的GitHub仓库。7期限未跟进的issue将会被自动关闭。


https://codesandbox.io/s/enqcp?file=/index.js

@afc163
Copy link
Member

afc163 commented Dec 3, 2020

还是判断一下好了,组件本身不做太多特殊处理。

(Array.isArray(option.props.children) ? option.props.children.join('') : option.props.children).toLowerCase()

@afc163 afc163 closed this as completed Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Need Reproduce We cannot reproduce your problem
Projects
None yet
Development

No branches or pull requests

3 participants