admin管理员组文章数量:1384278
All I want is to put this target icon inside the autoComplete ponent. I go through the documentation but could find a way.
In TextInput same thing can be achieved by doing this
<TextField
className={classes.margin}
id='input-with-icon-textfield'
label='TextField'
InputProps={{
startAdornment: (
<InputAdornment position='start'>
<AccountCircle />
</InputAdornment>
)
}}
/>
How can I add that target icon inside the autoComplete ponent? This is my code
Any help! Thanks in advance! =)
All I want is to put this target icon inside the autoComplete ponent. I go through the documentation but could find a way.
In TextInput same thing can be achieved by doing this
<TextField
className={classes.margin}
id='input-with-icon-textfield'
label='TextField'
InputProps={{
startAdornment: (
<InputAdornment position='start'>
<AccountCircle />
</InputAdornment>
)
}}
/>
How can I add that target icon inside the autoComplete ponent? This is my code
Any help! Thanks in advance! =)
Share Improve this question edited Mar 26, 2021 at 17:40 Kareem Dabbeet 3,9943 gold badges19 silver badges35 bronze badges asked Mar 26, 2021 at 17:07 margherita pizzamargherita pizza 7,22729 gold badges103 silver badges178 bronze badges 1-
Check out my answer of using
InputAdornment
. – Zunayed Shahriar Commented Mar 26, 2021 at 17:31
3 Answers
Reset to default 3Working solution with material's way using InputAdornment
at CodeSandbox.
Demo
Edit:
Base on your new requirement we need to use style.
And I've also changed your label condition to:
label={inputValue ? "" : "Near Me..."}
New demo at CodeSandbox.
Result:
Latest:
You could use style. Something like:
...
renderInput={(params) => (
<div>
<GpsFixedIcon className={classes.gpsIcon} /> //<-- style for icon
<TextField
{...params}
label="Add a location"
variant="outlined"
fullWidth
/>
</div>
)}
...
and in useStyles
:
const useStyles = makeStyles((theme) => ({
...
gpsIcon: {
position: "absolute",
top: "3%"
}
}));
Here your code modified.
InputAdornment
works with Autoplete
, you must pass the InputProps
from Autoplete to the TextField
.
<Autoplete
renderInput={(params) =>
<TextField
{...params}
label={'TextField'}
InputProps={{
...params.InputProps,
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
),
}}
/>
}
/>
本文标签: javascriptReact material UI icon insdie auto complete componentStack Overflow
版权声明:本文标题:javascript - React material UI icon insdie auto complete component - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744497383a2609112.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论