Reactjs 物料界面:如何在react中的输入字段中显示搜索图标?

Reactjs 物料界面:如何在react中的输入字段中显示搜索图标?,reactjs,redux,material-ui,Reactjs,Redux,Material Ui,我正在使用。我想在输入字段中显示搜索图标,如图所示 我正在使用 这是我的密码 我可以显示TextField,但无法添加搜索图标。 你能补充一下怎么补充吗 <TextField id="standard-bare" defaultValue="Bare" margin="normal" /> 您需要使用 例如: // imports import IconButton from "@material-ui/core/IconButton"; import InputAdornm

我正在使用。我想在输入字段中显示
搜索图标
,如图所示

我正在使用

这是我的密码

我可以显示
TextField
,但无法添加搜索图标。 你能补充一下怎么补充吗

 <TextField id="standard-bare" defaultValue="Bare" margin="normal" />

您需要使用

例如:

// imports
import IconButton from "@material-ui/core/IconButton";
import InputAdornment from "@material-ui/core/InputAdornment";
import SearchIcon from "@material-ui/icons/Search";

// render

<TextField
  label="With normal TextField"
  InputProps={{
    endAdornment: (
      <InputAdornment>
        <IconButton>
          <SearchIcon />
        </IconButton>
      </InputAdornment>
    )
  }}
/>
//导入
从“@material ui/core/IconButton”导入图标按钮;
从“@material ui/core/inputadornation”导入输入;
从“@material ui/icons/Search”导入SearchIcon;
//渲染
下面是一个演示:

const{
TextField,
输入,
IconButton,
搜索图标,
偶像
}=窗口['material-ui'];
类应用程序扩展了React.Component{
render(){
返回(
);
}
}
ReactDOM.render(,document.getElementById('root'))

您只需导入输入设置即可

从'@material ui/core/inputadornation'导入输入

然后像这样将InputProps添加到textField

InputProps={{
  endAdornment: (
    <InputAdornment position="start">
      <SearchIcon />
    </InputAdornment>
   )
  }}
InputProps={{
尾饰:(
)
}}
请查找所附的img,以演示您所需的解决方案


这里需要什么
IconButton
?让搜索图标可点击还是什么?@AlexMcMillan是的。图标基本上是一个SVG元素,因此您需要添加一个按钮。