gpt4 book ai didi

javascript - 不要使用 React-Select 清除选择时的输入

转载 作者:行者123 更新时间:2023-12-05 00:34:51 25 4
gpt4 key购买 nike

这个问题没有很好的答案,所以我会回答:
问题是如果你想使用 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
/>
)
}
Edit sharp-pike-rnjbr

关于javascript - 不要使用 React-Select 清除选择时的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64298547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com