gpt4 book ai didi

react-select - react-select 是否支持搜索中的 maxlength?

转载 作者:行者123 更新时间:2023-12-04 12:11:49 25 4
gpt4 key购买 nike

似乎在文档中没有提及它,我想将搜索限制为 n 个字符。

我可以通过添加 maxlength 在 Chrome 开发工具中成功尝试此操作属性到 input 元素,但我不知道如何告诉 react-select 组件这样做。

谢谢

最佳答案

由于 react-select v2 inputProps Prop 不再存在。在 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 }}
...
/>
);

关于react-select - react-select 是否支持搜索中的 maxlength?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49242789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com