Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material input | How to make 'focus' layout default

I'm using Angular Material in my application. I have input fields like this:

<mat-form-field appearance="outline">
  <mat-label>E-mail</mat-label>
  <input matInput placeholder="Indtast e-mail">
</mat-form-field>

Which produces a input form:

enter image description here

Focusing on the input form triggers an animation that transforms the input field to the following layout:

enter image description here

Question: Is it possible to have the "focus" layout (label floating in the top left corner) activated by default?

We wish to display the placeholder text, also when a field is not focused.

like image 327
Vingtoft Avatar asked Sep 12 '25 00:09

Vingtoft


1 Answers

You may set property floatLabel of mat-form-field to "always":

<mat-form-field appearance="outline" floatLabel="always">
  <mat-label>E-mail</mat-label>
  <input matInput placeholder="Indtast e-mail">
</mat-form-field>
like image 121
GCSDC Avatar answered Sep 14 '25 15:09

GCSDC