Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot change font size of text field in material ui

I am trying to learn material ui. I want to enlarge the text field on my page. However, the styles i embed with the field changes height, width and other properties except the size. Following is my code:

const styles = { container: {     display: 'flex',     flexWrap: 'wrap', }, textField: {     // marginLeft: theme.spacing.unit,     // marginRight: theme.spacing.unit,     width: 300,     margin: 100,     fontSize: 50 //??? Doesnt work } } 

Following is the stateless component(React):

const Searchbox = (props) => {      const { classes } = props;      return (         <TextField             onKeyDown={props.onKeyDown}             id="with-placeholder"             label="Add id"             placeholder="id"             className={classes.textField}             margin="normal"             autoFocus={true}             helperText={"Add an existing id or select "}         />     ); };  export default withStyles(styles)(Searchbox); 

I totally understand there is no rocket science as its a straightforward CSS in JS approach of applying styles.

However, I cannot override the base font size for my text field. Any help will be appreciated

like image 242
Omkar Avatar asked May 13 '18 19:05

Omkar


People also ask

How do I change the text field width in material UI?

Set MUI Width and Height with 'InputProps' 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}} .

How do I change TextField height in material UI?

To set the TextField height React Material UI, we can set the InputProps prop of the TextField to an object that has the classes property. to call makeStyles with a function that returns an object with the classes with height styles.


2 Answers

As mentioned in the page TextField API apply styles to the InputProps which applies style to the input element

Here is the code

const styles = {  container: {      display: 'flex',      flexWrap: 'wrap',  },  textField: {      width: 300,      margin: 100,  },  //style for font size  resize:{    fontSize:50  },  }

<TextField            id="with-placeholder"            label="Add id"            placeholder="id"            InputProps={{              classes: {                input: classes.resize,              },            }}            className={classes.textField}            margin="normal"          autoFocus={true}          helperText={"Add an existing id or select "}/>
like image 123
anonymous_siva Avatar answered Oct 13 '22 05:10

anonymous_siva


The most straight forward way to change the font size of both the input label and the input text is to use inline styling:

<TextField   label="input label name here"   margin="normal"   inputProps={{style: {fontSize: 40}}} // font size of input text   InputLabelProps={{style: {fontSize: 40}}} // font size of input label /> 

Edit QuizMaker

like image 21
AlienKevin Avatar answered Oct 13 '22 04:10

AlienKevin