【发布时间】:2018-08-06 11:34:36
【问题描述】:
我可以在使用 React-Select Creatable 时仅从下拉菜单中隐藏创建新选项吗?我想像往常一样展示其他建议,并希望保持创建新标签的可创建功能。只是不想在下拉菜单中显示用户正在输入的内容。
编辑:为 React-Select 添加示例代码:
import React, { Component } from 'react';
import CreatableSelect from 'react-select/lib/Creatable';
const colourOptions = [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' }
]
export default class CreatableMulti extends Component<*, State> {
handleChange = (newValue: any, actionMeta: any) => {
console.group('Value Changed');
console.log(newValue);
console.log(`action: ${actionMeta.action}`);
console.groupEnd();
};
formatCreate = (inputValue) => {
return (<p> Add: {inputValue}</p>);
};
render() {
return (
<CreatableSelect
isMulti
onChange={this.handleChange}
options={colourOptions}
formatCreateLabel={this.formatCreate}
createOptionPosition={"first"}
/>
);
}
}
这里还有一个沙盒链接:https://codesandbox.io/s/wqm0z1wlxl
当您键入 I want 时,它会显示 Add: 以及所有其他过滤的建议。我想从中删除添加部分以保留其余功能。
希望这对现在有帮助。
【问题讨论】:
-
您能否在问题中包含您目前编写的代码?
-
你有代码吗
-
只是为了综合你想要的,如果我理解得很好,你想要
Add:选项没有用户输入的单词?
标签: javascript reactjs react-select