I use Material-UI TextField with an Icon inside like this. The label "Your good name here" should be next to the icon instead of overlapping it.
This happens after I added InputLabelProps={{ shrink: false }} to the TextField.
How could I fix this position correctly? Any help!
Thanks in advance! =)
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import Input from "@material-ui/core/Input";
import InputLabel from "@material-ui/core/InputLabel";
import InputAdornment from "@material-ui/core/InputAdornment";
import FormControl from "@material-ui/core/FormControl";
import TextField from "@material-ui/core/TextField";
import Grid from "@material-ui/core/Grid";
import AccountCircle from "@material-ui/icons/AccountCircle";
const useStyles = makeStyles((theme) => ({
margin: {
margin: theme.spacing(1)
}
}));
export default function InputWithIcon() {
const classes = useStyles();
return (
<div>
<TextField
className={classes.margin}
id="input-with-icon-textfield"
label="Your good name here"
InputLabelProps={{ shrink: false }}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
)
}}
/>
<TextField
className={classes.margin}
id="input-with-icon-textfield"
label="Your good name here"
// InputLabelProps={{ shrink: false }}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
)
}}
/>
</div>
);
}
