I am trying to add just the default 14px padding-left set by startAdornment
and want to make it so the adornment takes up half of the TextField
instead. I can't seem to figure out how to style the startAdornment
in general.
I tried style the div itself, this works but there is still an underlying 14px padding left. I tried styling the InputAdornment
itself but it seems to have no effect.
InputProps={
this.state.didChange[rowIndex] ? {
startAdornment: (
<InputAdornment
position="start"
component="div"
style={{paddingLeft: '-14px'}}
disablePointerEvents>
<div style={{ backgroundColor: '#D3D4D0', marginLeft: '-14px', padding: "10px 13px", width: "26px", color: '#a1a39b' }}>
{prevVals[rowIndex]}
</div>
</InputAdornment>
)
} : null} />
This is the result of my current code:
This is what I want:
You can ignore the border color difference that doesn't matter I can change that.
MUI TextField Get ValueUse the onChange handler to get the current value from an MUI TextField. In this example I update a state value every time TextField value changes. This is the same state value that is passed to the TextField value prop in the Set Value example.
Another method for setting Material-UI TextField width and height is a combination of sx at the TextField root and passing sx styling values to the composing Input component via InputProps . The width is set with TextField prop sx={{width: 300}} . The height is set by passing sx: { height: 80 } to the InputProps prop.
there are adornedStart
and adornedEnd
classes in FilledInput and OutlinedInput classes.so you can either use them or use TextField
InputProps
dependig on what variant you use.
<TextField
name={'text'}
variant="outlined"
InputProps={{
endAdornment:
<IconButton onClick={()=>0}>x</IconButton>,
classes: {
adornedEnd: classes.adornedEnd
}
}}
/>
here is CodeSandbox
You can change the background color of the InputAdornment
by removing the padding left of the OutlinedInput
and set a matching padding in your adornment (based on the padding of the input here);
import MuiTextField from '@mui/material/TextField';
import { styled } from '@mui/material/styles';
const TextField = styled(MuiTextField)(({ theme }) => ({
'& .MuiOutlinedInput-root': {
paddingLeft: 0,
},
'& .MuiInputAdornment-root': {
backgroundColor: theme.palette.divider,
padding: '28px 14px',
borderTopLeftRadius: theme.shape.borderRadius + 'px',
borderBottomLeftRadius: theme.shape.borderRadius + 'px',
},
}));
<TextField
placeholder="Password"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<Visibility />
</InputAdornment>
),
}}
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With