Skip to content

Commit 9403ead

Browse files
authored
docs(form-field): add docs for appearance and mention that color type is supported (#10274)
* docs(form-field): add docs for `appearance` * add color to supported input types
1 parent 4d05cda commit 9403ead

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

src/lib/form-field/form-field.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ The following Angular Material components are designed to work inside a `<mat-fo
1313

1414
<!-- example(form-field-overview) -->
1515

16+
### Form field appearance variants
17+
The `mat-form-field` supports 4 different appearance variants which can be set via the `appearance`
18+
input. The `legacy` appearance is the default style that the `mat-form-field` has traditionally had.
19+
It shows the input box with an underline underneath it. The `standard` appearance is a slightly
20+
updated version of the `legacy` appearance that has spacing that is more consistent with the `fill`
21+
and `outline` appearances. The `fill` appearance displays the form field with a filled background
22+
box in addition to the underline. Finally the `outline` appearance shows the form field with a
23+
border all the way around, not just an underline.
24+
25+
There are a couple differences to be aware of between the `legacy` appearance and the newer
26+
`standard`, `fill`, and `outline` appearances. The `matPrefix` and `matSuffix` elements are center
27+
aligned by default for the newer appearances. The Material Design spec shows this as being the
28+
standard way to align prefix and suffix icons in the newer appearance variants. We do not recommend
29+
using text prefix and suffixes in the new variants because the label and input do not have the same
30+
alignment. It is therefore impossible to align the prefix or suffix in a way that looks good when
31+
compared with both the label and input text.
32+
33+
The second important difference is that the `standard`, `fill`, and `outline` appearances do not
34+
promote placeholders to labels. For the `legacy` appearance specifying
35+
`<input placeholder="placeholder">` will result in a floating label being added to the
36+
`mat-form-field`. For the newer variants it will just add a normal placeholder to the input. If you
37+
want a floating label, add a `<mat-label>` to the `mat-form-filed`.
38+
39+
<!-- example(form-field-appearance) -->
40+
1641
### Floating label
1742

1843
The floating label is a text label displayed on top of the form field control when

src/lib/input/input.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ also contains an `<mat-placeholder>` element.
1717

1818
The following [input types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) can
1919
be used with `matInput`:
20+
* color
2021
* date
2122
* datetime-local
2223
* email
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<p>
2+
<mat-form-field appearance="legacy">
3+
<mat-label>Legacy form field</mat-label>
4+
<input matInput placeholder="Placeholder">
5+
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
6+
<mat-hint>Hint</mat-hint>
7+
</mat-form-field>
8+
</p>
9+
<p>
10+
<mat-form-field appearance="standard">
11+
<mat-label>Standard form field</mat-label>
12+
<input matInput placeholder="Placeholder">
13+
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
14+
<mat-hint>Hint</mat-hint>
15+
</mat-form-field>
16+
</p>
17+
<p>
18+
<mat-form-field appearance="fill">
19+
<mat-label>Fill form field</mat-label>
20+
<input matInput placeholder="Placeholder">
21+
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
22+
<mat-hint>Hint</mat-hint>
23+
</mat-form-field>
24+
</p>
25+
<p>
26+
<mat-form-field appearance="outline">
27+
<mat-label>Outline form field</mat-label>
28+
<input matInput placeholder="Placeholder">
29+
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
30+
<mat-hint>Hint</mat-hint>
31+
</mat-form-field>
32+
</p>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {Component} from '@angular/core';
2+
3+
/** @title Form field appearance variants */
4+
@Component({
5+
selector: 'form-field-appearance-example',
6+
templateUrl: 'form-field-appearance-example.html',
7+
styleUrls: ['form-field-appearance-example.css']
8+
})
9+
export class FormFieldAppearanceExample {}

0 commit comments

Comments
 (0)