I´m having some issues with how my elements are aligned on Material UI.
This is the code of my Input and Select elements:
<div>
<form>
<TextField
label="Search"
/>
<FormControl>
<InputLabel htmlFor="age-simple">Age</InputLabel>
<Select
value=""
onChange=""
inputProps={{
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
</form>
</div>
And this is the output that I get:
MUI TextField Text Align Right, Left, and Center In the code below, I targeted the input element that renders as a child of the root div of the Input component within the TextField. Simply set the value to "right" to get right alignment. Left is the default value.
We can use TextField component in Material UI to show input textbox. import TextField from "@material-ui/core/TextField"; When using the TextField component, we can pass the required attribute to mark the component as required.
Simply put, in MUI the FormControl is for controlling state and other data while the FormGroup is mostly for layout. The FormControl component will generally be wrapping one or many FormGroup components.
You can use flexbox to align multiple form fields. You just need to add display: flex
to the parent element. In the following example I used inline styles, but you could use any of the supported style solutions.
There is also an error in your code: inputProps={{
is missing the closing brackets: }}
const { React, ReactDOM } = window
const { InputLabel, FormControl, TextField, MenuItem, Select } = window['material-ui']
const Form = () => (
<form style={{ display: 'flex' }}>
<TextField label="search" />
<FormControl>
<InputLabel htmlFor="age-simple">Age</InputLabel>
<Select value="">
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
</form>
)
ReactDOM.render(<Form />, document.querySelector('#root'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react-dom.min.js"></script><script src="https://unpkg.com/[email protected]/umd/material-ui.production.min.js"></script><div id="root"></div>
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