I want the search icon to appear on the right side of the input box in material-ui (react). Are there any classes to be added for this?
我希望搜索图标出现在材料-用户界面(反应)中输入框的右侧。是否需要为此添加任何类?
here is the code snippet
下面是代码片段
import InputBase from '@material-ui/core/InputBase';
import SearchIcon from '@material-ui/icons/Search';
<div className={classes.search}>
<div className={classes.searchIcon}>
<SearchIcon />
</div>
<InputBase
placeholder="Search…"
classes={{
root: classes.inputRoot,
input: classes.inputInput,
}}
inputProps={{ 'aria-label': 'search' }}
/>
</div>
更多回答
Share the code snippet you are using for this. Just the image would not help to provide the solution.
共享您为此使用的代码片段。仅仅是图像并不能帮助提供解决方案。
优秀答案推荐
Use endAdornment
in InputBase
:
在InputBase中使用endAdornment:
<InputBase
placeholder="Search…"
inputProps={{ 'aria-label': 'search' }}
endAdornment={<SearchIcon/>}
/>
In Place of endAdornment
just put startAdornment
that will work.
用startAdornment代替endAdornment就可以了。
Here is my Code as an Example
以下是我的代码示例
import Button from "@mui/material/Button";
import { Container, InputAdornment, TextField } from "@mui/material";
import { useState } from "react";
import SearchIcon from "@mui/icons-material/Search";
const MyFilesIndex = () => {
const [searchTerm, setSearchTerm] = useState("");
const handleChange = (event: any) => {
setSearchTerm(event.target.value);
};
return (
<div>
<Container maxWidth="md">
<TextField
id="search"
type="search"
placeholder="Search"
value={searchTerm}
onChange={handleChange}
sx={{ width: 350 }}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<SearchIcon />
</InputAdornment>
)
}}
/>
</Container>
</div>
);
更多回答
我是一名优秀的程序员,十分优秀!