Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

center input text in a mui TextField

My TextField input wont center. I am using mui TextField to build a form.

Can anyone help, I have been trying a few different things but I can get it to work.

  <TextField
        size="small"
        id="username"
        placeholder="Username"
        type="email"
        value={values.username}
        error={touched.username && !!errors.username}
        helperText={touched.username ? errors.username : ''}
        onChange={handleChange('username')}
        onBlur={handleBlur('username')}
        variant="outlined"
        InputProps={{ className: classes.input }}
      />



const useStyles = makeStyles(() => ({
  input: {
    display: 'flex',
    justifyContent: 'center',
    textAlign: 'center',
  },
  inputCenter: {
    textAlign: 'center',
    color: 'red',
  },
}));

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you are using MUI v5 I think for text alignment you can use sx prop of mui :

<TextField
    InputProps={{
        sx: {
            "& input": {
                textAlign: "center"
            }
        }
    }}
/>

reference : The sx prop

Or if you are using MUI v4 try :

 inputProps={{
        style: { textAlign: "center" }
      }}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading