【发布时间】:2020-07-05 16:56:12
【问题描述】:
我正在尝试使用 react-select 创建一个 select 元素,并为此使用 Createable 组件。
在我当前的实现中,它不会在输入时提示用户输入“创建”选项,如documentation 所示 它将显示默认的“无选项”。
我也在使用redux-form 库,但我认为问题不在于那里。
到目前为止,这是我的代码:
import Select from "react-select/creatable";
import React from "react";
const customFilter = (option, searchText) => {
return option.data.searchfield.toLowerCase().includes(searchText.toLowerCase());
};
export default (props) => {
const { input, options, placeholder } = props;
const renderValue = (value) => {
const val =
value === "" ? null : options.find((obj) => obj.value === input.value);
return val || "";
};
return (
<Select
value={renderValue(input.value)}
name={input.name}
onFocus={() => input.onFocus(input.value)}
onChange={(value) => input.onChange(value.value)}
onBlur={() => input.onBlur(input.value)}
options={options}
isRtl={true}
placeholder={placeholder}
filterOption={customFilter}
/>
);
};
编辑:
我还尝试从文档中导入 makeCreatableSelect ,但没有帮助:
import Creatable, { makeCreatableSelect } from 'react-select/creatable';
<Creatable
//here goes props
/>
【问题讨论】:
标签: javascript reactjs redux-form react-select