【发布时间】:2021-05-05 16:43:17
【问题描述】:
我正在尝试使用 readOnly 设置为 True 来实现材料 ui 自动完成。我从各个论坛了解到 inputProps 属性会覆盖 params 的 InputProps 参数。但是,我尝试了建议的解决方法,但也失败了。找到下面的代码sn-p。
<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 }}
/>
)}
/>
【问题讨论】:
-
你想用
readOnly: true做什么?我将您的示例放入codesandbox.io/s/…,它似乎按预期工作——我无法直接向框中添加文本,我只能通过在下拉列表中选择项目来向自动完成添加内容。