我在用反应选择 https://github.com/JedWatson/react-select库在我的项目中实现搜索和选择功能。
作为基本用法,我只能选择搜索后返回的选项。看起来像this https://i.stack.imgur.com/m9RTF.png其代码是:
<AsyncSelect
onChange={(item) => _selectedItemChange(item)}
loadOptions={loadItemOptions}
placeholder='Start typing'
/>
现在,我想要在选择框的下端有一个按钮,以便我可以执行“未找到?”之类的操作。添加“新”类型的东西。就像是this https://i.stack.imgur.com/WRFd8.png。我还希望该按钮的 onClick 函数是我自己的。
我怎样才能做到这一点?
import { components } from 'react-select';
const SelectMenuButton = (props) => {
return (
<components.MenuList {...props}>
{props.children}
<button>Add new element</button>
</components.MenuList >
) }
<Select components={{ MenuList: SelectMenuButton }} />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)