gpt4 book ai didi

Material-ui search icon needed to be in right side of input box(素材-用户界面搜索图标需要位于输入框的右侧)

转载 作者:bug小助手 更新时间:2023-10-24 17:54:51 26 4
gpt4 key购买 nike



Material UI search input



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>
);

更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com