index.js
import React from 'react' import TextField from '@material-ui/core/TextField' import style from './style' import withStyles from 'hoc/withStyles' import { connect } from 'react-redux' class SearchField extends React.Component { constructor (props) { super(props) this.onChange = this.onChange.bind(this) } onChange (event) { const { dispatcher } = this.props this.props.dispatch(dispatcher(event.target.value)) event.preventDefault() } render () { const { classes, placeholder } = this.props return ( <TextField label={placeholder} placeholder={placeholder} InputProps={{ classes: { input: classes.resize } }} className={classes.textField} margin="normal" autoFocus={true} variant="outlined" onChange={this.onChange} /> ) } } export default withStyles(style)(connect()(SearchField))
style.js
export default function () { return { container: { display: 'flex', flexWrap: 'wrap' }, textField: { width: 'auto' }, resize: { fontSize: 11 } } }
https://material-ui.com/api/text-field/
How can I change TextField
height? I can't find it in the documentation. When I try to change it directly in CSS it works incorrectly (it looks like this - selected height on the screen 26px).
What should I do?
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.
To change font size of text field in React Material UI, we can set the InputProps and the InputLabelProps prop to set the font size of the input box and the input label respectively. to set InputProps and InputLabelProps to { style: { fontSize: 40 } } so that the input box and the label both have font size 40px.
To style a React Material UI text field, we can call the makeStyles function with a function that returns an object that specifies the styles. Then we can set the InputProps prop of the TextField to specify the styles of the input element in the text field.
Material-UI Icon Size There are two ways to update the size of the icon: use the fontSize prop available on the icon or set the font-size CSS style. These are both options whether the icon is inside a button or independent of a button.
You can try out adding the size="small" which is mentioned in the Textfield API
<TextField variant="outlined" size="small" / >
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