soma iyappan
soma iyappan

Reputation: 542

How to change Material-UI TextField InputAdornment background color?

First 10% one background color ,another 90% another background color.

<TextField
  className={classes.root}                  
  type="text"
  placeholder="username"
  variant="outlined"
  style={{borderRadius:'50',
    backgroundColor: "white"
  }}
  InputProps={{
    startAdornment: (
      <InputAdornment position="start">
        <PersonIcon />
      </InputAdornment>
    )
  }}
/>

I attach demo textfield in below

enter image description here

Upvotes: 7

Views: 12782

Answers (2)

Durai DD
Durai DD

Reputation: 187

enter image description here

You can do this in simple way .Try this one

InputProps={{
                startAdornment: (
                  <div style={{display:'flex',flexDirection:'column',justifyContent:'center',alignContent:'center', backgroundColor:'#E1E8EB',height:55,width:50,marginLeft:-13,border:'0px solid green',marginRight:5}}>
                  <InputAdornment position="start">
                    
                    <VpnKeyIcon style={{marginLeft:10}} />
                    
                  </InputAdornment>
                  </div>
                )
              }}

Upvotes: 2

NearHuscarl
NearHuscarl

Reputation: 81270

This is how you override the InputAdornment to achieve the same effect in your screenshot. Note that the input next to the InputAdornment has its box-sizing set to content-box, so it's not as simple as setting the height to 100% in the adornment. I had to copy the padding code here to make sure the height of the adornment is the same as the height of the OutlinedInput:

<TextField
  placeholder="With normal TextField"
  sx={{
    "& .MuiOutlinedInput-root": {
      paddingLeft: 0
    }
  }}
  InputProps={{
    startAdornment: (
      <InputAdornment
        sx={{
          padding: "27.5px 14px",
          backgroundColor: (theme) => theme.palette.divider,
          borderTopLeftRadius: (theme) =>
            theme.shape.borderRadius + "px",
          borderBottomLeftRadius: (theme) =>
            theme.shape.borderRadius + "px"
        }}
        position="start"
      >
        kg
      </InputAdornment>
    )
  }}

Live Demo

V5

Codesandbox Demo

V4

Codesandbox Demo

Upvotes: 5

Related Questions