Skip to content

Commit b98138b

Browse files
committed
docs(material/form-field): update documentation about the form-field appearances
1 parent 34dd468 commit b98138b

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/components-examples/material/form-field/form-field-harness/form-field-harness-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<mat-form-field id="with-errors">
1+
<mat-form-field id="with-errors" appearance="fill">
22
<span class="custom-control">Custom control harness</span>
33
<input matInput [formControl]="requiredControl">
44

src/material/form-field/form-field.md

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,52 @@ The following Angular Material components are designed to work inside a `<mat-fo
1616

1717
### Form field appearance variants
1818
The `mat-form-field` supports 4 different appearance variants which can be set via the `appearance`
19-
input. The `legacy` appearance is the default style that the `mat-form-field` has traditionally had.
20-
It shows the input box with an underline underneath it. The `standard` appearance is a slightly
21-
updated version of the `legacy` appearance that has spacing that is more consistent with the `fill`
22-
and `outline` appearances. The `fill` appearance displays the form field with a filled background
23-
box in addition to the underline. Finally the `outline` appearance shows the form field with a
24-
border all the way around, not just an underline.
25-
26-
There are a couple differences to be aware of between the `legacy` appearance and the newer
27-
`standard`, `fill`, and `outline` appearances. The `matPrefix` and `matSuffix` elements are center
28-
aligned by default for the newer appearances. The Material Design spec shows this as being the
29-
standard way to align prefix and suffix icons in the newer appearance variants. We do not recommend
30-
using text prefix and suffixes in the `fill` and `outline` variants because the label and input do not have the same
31-
alignment. It is therefore impossible to align the prefix or suffix in a way that looks good when
32-
compared with both the label and input text.
33-
34-
The second important difference is that the `standard`, `fill`, and `outline` appearances do not
19+
input. The `legacy` and `standard` appearances implement an older version of the spec where
20+
`mat-form-field` had an underline beneath it. We recommend not using these variants as they do not
21+
match the current spec.
22+
23+
The `fill` an `outline` appearances implement the current version of the spec. The `fill` appearance
24+
displays the form field with a filled background box in addition to an underline, and the `outline`
25+
appearance shows the form field with a border all the way around, rather than just an underline.
26+
27+
There are a couple differences in behavior to be aware of between the different appearances.
28+
The `matPrefix` and `matSuffix` elements are center aligned by default for the `fill` and `outline`
29+
appearances. The Material Design spec shows this as being the standard way to align prefix and
30+
suffix icons.
31+
32+
We recommend that text prefix and suffixes in the `fill` and `outline` variants only be used in
33+
conjunction with the `floatLabel="always"` option. This is because the label and input do not have
34+
the same alignment, and it is therefore impossible to align the prefix or suffix in a way that looks
35+
good when compared with both the resting (non-floating) label and input text. We plan to improve
36+
support for text prefix and suffixes in the future so they can be used without
37+
`floatLabel="always"`.
38+
39+
The final important difference is that the `standard`, `fill`, and `outline` appearances do not
3540
promote placeholders to labels. For the `legacy` appearance specifying
3641
`<input placeholder="placeholder">` will result in a floating label being added to the
3742
`mat-form-field`. For the newer variants it will just add a normal placeholder to the input. If you
3843
want a floating label, add a `<mat-label>` to the `mat-form-field`.
3944

45+
Out of the box, if you do not specify an `appearance` for the `<mat-form-field>` it will default to
46+
`legacy`. However, this can be configured using a global provider to choose a different default
47+
appearance for your app.
48+
49+
```ts
50+
@NgModule({
51+
providers: [
52+
{provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {appearance: 'fill'}}
53+
]
54+
})
55+
```
56+
4057
<!-- example(form-field-appearance) -->
4158

4259
### Floating label
4360

4461
The floating label is a text label displayed on top of the form field control when
45-
the control does not contain any text or when `<select matNativeControl>` does not show any option text.
46-
By default, when text is present the floating label
47-
floats above the form field control. The label for a form field can be specified by adding a
48-
`mat-label` element.
62+
the control does not contain any text or when `<select matNativeControl>` does not show any option
63+
text. By default, when text is present the floating label floats above the form field control. The
64+
label for a form field can be specified by adding a `mat-label` element.
4965

5066
In the legacy version of the `<mat-form-field>` (one that has no `appearance` attribute or has
5167
`appearance="legacy"`) if a label is not specified, the `placeholder` attribute on the form control

0 commit comments

Comments
 (0)