Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep MUI TextField label on top when text field has no value

So this should be simple but I don't see a clear answer. The labels I have looks like this:

enter image description here.

As you can see the bottom 2 fields have the label on top since they have a default value whereas the top on "ML Features" does not and the label moves to the middle of the TextField.

The code looks like this:

<TextField
    label="ML Features" // or any other field
    ...
   >
</TextField>

How can I keep the label always on the top?

like image 520
Michael Avatar asked Oct 12 '20 07:10

Michael


1 Answers

You can set shrink to true in InputLabelProps. For more reference, see InputLabel API here.

<TextField label="ML Features" InputLabelProps={{ shrink: true }} />
like image 110
NearHuscarl Avatar answered Nov 02 '22 19:11

NearHuscarl