如何在不删除自动完成中的选择的情况下禁用 Material-UI 中的下划线?

问题描述

我想用没有下划线的 Autocomplete 组件创建 TextField。我在 InputProps={{ disableunderline: true }} 道具中使用 TextField 禁用了下划线,它完成了它的工作,但它也删除了选择栏,所以问题是,如何在不删除选择栏的情况下完成此操作?

解决方法

要再次启用下拉列表,您还需要在嵌套属性中传播所有提供的道具 (InputProps)。所以替换这一行

<TextField {...params} InputProps={{ disableUnderline: true }} />

与:

<TextField {...params} InputProps={{ ...params.InputProps,disableUnderline: true }} />

完整的工作代码:

<Autocomplete
  options={top100Films}
  getOptionLabel={(option) => option.title}
  style={{ width: 300 }}
  renderInput={(params) => (
    <TextField
      {...params}
      InputProps={{ ...params.InputProps,disableUnderline: true }}
      label="Combo box"
    />
  )}
/>

现场演示

Edit 67142906/how-can-i-disable-underline-in-material-ui-without-removing-the-selection-in-aut

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...