Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI InputLabel - disable animation when input is empty

Tags:

material-ui

When my input field is empty and not focused, Material UI would place the label inside the input field as a placeholder.

enter image description here

What I want is, to have the label above the input field all the times, similarly to what it looks like if the input field is selected.

enter image description here

How can I do this?

Example code:

     <FormControl>
        <InputLabel htmlFor="name">Name</InputLabel>
        <Input name="name"
               value={name}/>
      </FormControl>
like image 652
Anton Belev Avatar asked Dec 23 '22 22:12

Anton Belev


2 Answers

For those looking for how to achieve this with TextField component, here:

<TextField
  variant="outlined"
  InputLabelProps={{
    shrink: true,
  }}
/>
like image 68
DedaDev Avatar answered Mar 23 '23 19:03

DedaDev


After 30 mins of pulling my hair... I finally got it. The property you are looking for is not called disableAnimation as one could thought, it's the shrink property. API docs - https://material-ui.com/api/input-label/

  <FormControl>
    <InputLabel htmlFor="name" shrink='true'>Name</InputLabel>
    <Input name="name"
           value={name}/>
  </FormControl>

enter image description here

like image 43
Anton Belev Avatar answered Mar 23 '23 20:03

Anton Belev