使用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
当您键入时,我希望它显示一个“添加:”以及所有其他过滤的建议。我想从中删除添加部分,以保留其余功能。
希望这会有所帮助。
答案 0 :(得分:3)
如果您要替换选项Meteor.loginWithToken
,可以在Add: myValue
中使用道具formatCreateLabel
,如下所示:
CreatableSelect
Here a live example,并将先前的代码应用于您给出的示例。 您可以咨询文档版权here来了解此特定道具的行为。