文档中似乎没有提及它,我想将搜索限制为 n 个字符。
我可以通过向输入元素添加属性来在 Chrome 开发工具中成功尝试此操作maxlength,但我不确定如何告诉反应选择组件执行此操作。
谢谢
由于react-select v2 inputPropsprop不再存在。在react-select v2+中,您应该使用Components API。在这种情况下,代码可能如下所示:
import React from "react";
import Select, { components } from "react-select";
const Input = props => <components.Input {...props} maxLength={5} />;
export default () => (
<Select
...
components={{ Input }}
...
/>
);
Run Code Online (Sandbox Code Playgroud)
这就是应用 maxLength 的方法
作为 prop传递maxLength或在文件中定义
<Select
...
onInputChange={inputValue =>
(inputValue.length <= maxLength ? inputValue : inputValue.substr(0, maxLength))
}
....
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5606 次 |
| 最近记录: |