reactjs - Material UI 5.0:当自动完成值为空时,每个项目都被选中
问题描述
当前行为
当 Input 为 null 时,样式突出显示为灰色光(类似这样)
这是我当前的代码
<Field
name="day"
render={({ input }) =>
<Autocomplete
options={this.days}
getOptionLabel={(option) => {
return option.toString()
}}
{...input}
onChange={(e, val) => {
input.onChange(val);
}}
isOptionEqualToValue={(option, value) => {
if (value === "" || value === option)
return true;
}}
renderInput={(params) => <TextField {...params} label="Day" variant="outlined" />}
/>
} />
注意:我对 react-final-form 使用“Field”包装器(因为 mui-rff 尚未升级到 MUI 5.0)
预期行为
在这张图片上,当我选择一个值时,它与我的选项数组匹配并且样式恢复正常。
语境
铬:94.0.4606.71解决方案
最后我找到了解决方案。
我需要通过添加此选项来{...input}
作为第一个道具移动: 。options={this.days}
value={null}
注意你声明的地方{...input}
。
推荐阅读
- css - CSS 选择器:“仅在没有父 Y 时选择 X”
- android - 在使用 Retrofit 调用获取 Web 服务请求时。“android.os.TransactionTooLargeException:数据包大小 1575704 字节”
- firebase - Angular 6,Firebase 存储网络图片库
- mysql - 在 MySQL 中选择多于一行的特定值和条件依赖项
- c++ - 在 Windows 和 Clion 上使用 OpenCV
- javascript - jQuery 对话框 - 内部 html 超链接
- python - 使用 selenium python 来自 tradingview 的数据
- excel - 构造一个嵌套的if excel公式
- javascript - 如何修改缩小的 javascript 文件以及随附的源映射?
- c# - 如何关闭所有从 .NET 继承的句柄