autocomplete - inputProps={{ readOnly: true }} 不适用于 Material UI 自动完成
问题描述
我正在尝试使用 readOnly 设置为 True 来实现材料 ui 自动完成。我从各个论坛了解到 inputProps 属性会覆盖 params 的 InputProps 参数。但是,我尝试了建议的解决方法,但也失败了。在下面的代码片段下面找到。
<Autocomplete
multiple
id="listvalues"
options={top100Films}
getOptionLabel={(option) => option.title}
filterSelectedOptions
renderInput={(params) => (
<TextField
{...params}
variant="outlined"
label="filterSelectedOptions"
placeholder="Favorites",
inputProps={{...params.inputProps, readOnly: true }}
/>
)}
/>
解决方案
inputProps 与 InputProps 不同
InputProps={{ ...params.InputProps, readOnly: true, }}