I'm trying to make a form using Material UI
and React
. This is what I have so far:
import React from 'react'
import {Button, TextField} from '@material-ui/core'
import AddIcon from '@material-ui/icons/Add'
import PropTypes from 'prop-types'
class AddItem extends React.Component {
state = {
text: ''
}
handleChange = e => {
this.setState({text: e.target.value})
}
render() {
return (
<form onSubmit={this.props.onSubmit(this.state.text)}>
<TextField id="task" label="Task" placeholder="e.g. Feed the fish" value={this.state.text}
onChange={this.handleChange} color="secondary" variant="outlined" size="small"/>
<Button color="secondary" variant="outlined" endIcon={<AddIcon/>} size="large">
Add
</Button>
</form>
)
}
}
AddItem.propTypes = {
onSubmit: PropTypes.func.isRequired
}
export default AddItem
The result is the following screenshot:
But wait! Can you see that? The Button
height and the TextField
height are just so slightly misaligned! (By 2.5px I think). Is there any way to fix this?
This is better than earlier, where the TextField was a lot bigger than the Button (my fix was size="small"
on the TextField).
How can I make sure that the TextField and the Button are the same height?
I know that in Bulma there's something like a level
component that helps out with that, so is there any similar solution in Material UI
?