0

Is there a way to achieve a normal inpout biox with angular material 2? such as the imageenter image description here

When ever i refer to the Docs In only see inputs where when click the placeholder text floats up.

Charles L.
  • 1,844
  • 2
  • 34
  • 56

2 Answers2

2

You can use floatLabel="never" on your mat form field:

<mat-form-field appearance="legacy" floatLabel="never">
    <mat-label>Search here</mat-label>
    <input matInput>
    <mat-icon matSuffix>search</mat-icon>
</mat-form-field>

You cannot combine it with the appearance="outline" like in your example image as stated in the docs:

Note: only the legacy appearance supports the never option. never was originally added as a way to make the floating label emulate the behavior of a standard input placeholder. However the form field now supports both floating labels and placeholders. Therefore in the non-legacy appearances the never option has been disabled in favor of just using the placeholder.

Tim Martens
  • 1,464
  • 9
  • 18
1

I use this code in my project it is the same as your input but has an underline in the bottom of the input

I just make some changes in mat-form-field style

<mat-form-field   style="padding:3px;border-radius:60px;border-style:solid; border-color:#c0bfbf91;border-width:1px">
    <input matInput  value="Sushi">
  <mat-icon  matSuffix>search</mat-icon>
      <mat-placeholder style="margin-left:20px">Favorite food</mat-placeholder>
  </mat-form-field>
Rabea AlTaradeh
  • 213
  • 1
  • 9
  • I strongly suggest that you utilise CSS classes instead of inline styles as it's considered a bad practice and may cause code readability problems. – Edric Jul 03 '18 at 15:12
  • Yup... I added the solution when I am in working ... thanks for suggest – Rabea AlTaradeh Jul 04 '18 at 10:07