I am trying to both center align the text inside and set a min number value to 0. But that is not occurring. I can do either or but not both at the same time. I looked at the material-ui page on TextField but it was no help --> here
<TextField type="number"
id={cells.id}
inputProps={{min: 0}}
InputProps={classes.inputText}
className={classes.inputComponent}
disabled={cells.disabled}
defaultValue={cells.text} />
I need to set a style for the text field itself and style for the text inside.
inputComponent: {
height: '30px',
width: '71px',
border: '1px solid #D3D4D0',
borderRadius: '5px',
backgroundColor: '#FFFFFF',
boxShadow: '0 1px 0 0 rgba(170,170,170,0.01)'
}
inputText: {
color: 'rgba(0,0,0,0.87)',
fontSize: '16px',
letterSpacing: '0.5px',
lineHeight: '28px',
textAlign: 'center',
}
left: It aligns text along the left side of a page or containing element. It is the default value. right: It aligns text along the right side of a page or containing element. center: Text is aligned around a midpoint. justify: To make sure that both edges of each line are aligned with both margins, space is added between words.
The Typography component of Material UI is used to present your text and content as clearly and efficiently as possible. import Typography from '@material-ui/core/Typography'; // OR import { Typography } from '@material-ui/core'; Syntax: It sets the alignment property. left: It aligns text along the left side of a page or containing element.
The name MuiTextField can be used when providing default props or style overrides in the theme. Props of the FormControl component are also available. This prop helps users to fill forms faster, especially on mobile devices. The name can be confusing, as it's more like an autofill. You can learn more about it following the specification.
Consider either: The name MuiTextField can be used when providing default props or style overrides in the theme. Props of the FormControl component are also available. This prop helps users to fill forms faster, especially on mobile devices. The name can be confusing, as it's more like an autofill.
UPDATE Material UI 5
With the new version of Material UI, the inputProps is one level deeper.
<TextField
InputProps={{
inputProps: {
style: { textAlign: "right" },
}
}}
/>
Change JSX a little:
<TextField type="number"
id={cells.id}
inputProps={{min: 0, style: { textAlign: 'center' }}} // the change is here
InputProps={classes.inputText}
className={classes.inputComponent}
disabled={cells.disabled}
defaultValue={cells.text} />
Reason
InputStyle
is not part of the API anymore.
You need to use it as style: {}
inside inputProps
the same way as InputStyle
before.
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