这个问题没有很好的答案,所以我会回答:
问题是如果你想使用 React-Select 并且你想要在选择或模糊时不会被清除的持久输入值。该组件当前不支持此功能,因此需要解决方法。
我还就该主题提出的几个问题之一回答了这个问题
https://github.com/JedWatson/react-select/issues/588
https://github.com/JedWatson/react-select/issues/3210
最佳答案
您也可以使用 this 来增加它得到想要的效果
const App = () => {
const [input, setInput] = useState("");
const [inputSave, setSave] = useState("");
return (
<Select
placeholder={inputSave} // when blurred & value == "" this shows
value="" // always show placeholder
inputValue={input} // allows you continue where you left off
onInputChange={setInput} // allows for actually typing
onMenuClose={() => setSave(input)} // before the input is cleared, save it
onFocus={() => {
setInput(inputSave);
setSave(""); // prevents undesired placeholder value
}}
blurInputOnSelect // actually allows for ^^ to work
/>
)
}
关于javascript - 不要使用 React-Select 清除选择时的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64298547/