【问题标题】:inputProps={{ readOnly: true }} doesn't work for Material UI AutocompleteinputProps={{ readOnly: true }} 不适用于 Material UI 自动完成
【发布时间】: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/…,它似乎按预期工作——我无法直接向框中添加文本,我只能通过在下拉列表中选择项目来向自动完成添加内容。

标签: autocomplete material-ui


【解决方案1】:

inputProps 与 InputProps 不同

InputProps={{ ...params.InputProps, readOnly: true, }}

【讨论】:

    猜你喜欢
    • 2020-03-06
    • 2020-07-29
    • 1970-01-01
    • 2020-05-05
    • 2015-08-05
    • 2023-03-24
    • 2015-10-16
    • 2021-08-05
    • 2020-12-14
    相关资源
    最近更新 更多