placeholder loaction in mat-input
Asked Answered
B

1

5

I'm using angular6 with angular material to create this neat website.

I'm using a mat-form-field with mat-input so show a text input element with a placeholder text.

the placeholder text position has two states.

one! when the text input is empty and you are not focused into that element:

empty mat-input

and the other when you focused on the input text and/or you the input text is not empty

mat-input with text

I want the mat-input element to be in the 2nd state. to show the placeholder above the text input element even when there is no text in it and i'm not focused on that element.

I know i can make a work-around and add some sort of empty space to the value of the element.. but is there a more elegant way to achieve what I need?

thanks!!!

Beyer answered 23/9, 2018 at 18:24 Comment(0)
G
11

You can use floatLabel="always", which is the input property binding for mat-form-field

<mat-form-field style="width: 100%" floatLabel="always">
  <input matInput placeholder="Enter Name">
</mat-form-field>

Working Stackblitz

Garibull answered 23/9, 2018 at 18:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.