When creating custom styling with Material UI + redux-form, the Field element from redux-form does not apply the custom class names. When simply using FieldText from Material UI does. I have commented out the non-functioning line of code below.
The custom styles object is being applied the the react component via a prop named 'classes' that is defined on the prototype.
import React, {Component} from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField';
import { Field, reduxForm } from 'redux-form';
import { connect } from 'react-redux';
import {createOrder} from '../actions';
const styles = theme => ({
root: {
display: 'flex',
flexWrap: 'wrap',
justifyContent: 'center'
},
margin: {
margin: theme.spacing.unit,
},
textField: {
flexBasis: 400,
},
button: {
margin: theme.spacing.unit,
},
input: {
display: 'none',
},
});
class Order extends Component {
renderField(field) {
return (
<div>
<TextField
id="outlined-simple-start-adornment"
// className={classNames(classes.margin, classes.textField)}
variant="outlined"
label="Age"
{...field.input}
/>
</div>
)
}
render() {
const { classes } = this.props;
return (
<form >
<div className={classes.root}>
<Field
name="age"
label="age"
component={this.renderField}
/>
<TextField
id="outlined-simple-start-adornment"
className={classNames(classes.margin, classes.textField)}
variant="outlined"
label="Company Name"
/>
</div>
</form>
);
}
}
Order.propTypes = {
classes: PropTypes.object.isRequired,
};
export default reduxForm({
form: 'Form'
})(
connect(null, {createOrder})(withStyles(styles)(Order))
);