Your question's comments are partially accurate. Editing the actual <input>
element may result in losing functionality, however, the Textfield
component is more than just an <input>
. It consists of multiple elements that can potentially display an image.
Assuming you are using the latest MUI version since it wasn't specified, achieving this is possible by utilizing the MUI 4 TextField
with the old makeStyles
function.
To adjust the positioning of the startAdornment
in the TextField
, you need to make some CSS modifications. By changing the default flex-direction
from row
to column
and tweaking the gutters, you can achieve the desired layout:
<TextField
id="input-with-icon-textfield"
label="TextField"
variant="outlined"
sx={{
".MuiOutlinedInput-root": {
paddingTop: "1rem",
flexDirection: "column"
},
img: {
paddingRight: "1rem"
}
}}
InputProps={{
startAdornment: <img src="https://via.placeholder.com/180x150/200" />
}}
placeholder="Enter image caption..."
/>
This code will generate the following output:
https://i.sstatic.net/AhvVS.png
For a functional example, visit: https://codesandbox.io/s/inputwithicon-material-demo-forked-tyx7y?file=/demo.js:139-580