Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI Input aligned to Select

Tags:

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:

enter image description here

like image 417
Marcelo Avatar asked Apr 11 '18 13:04

Marcelo


People also ask

How do you align text in TextField MUI?

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.

How do you make a text field mandatory in material UI?

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.

What is FormControl MUI?

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.


1 Answers

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>
like image 130
Luke Peavey Avatar answered Sep 28 '22 06:09

Luke Peavey