@@ -16,36 +16,49 @@ The following Angular Material components are designed to work inside a `<mat-fo
16
16
17
17
### Form field appearance variants
18
18
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.
19
+ input. The ` fill ` an ` outline ` appearances implement the current version of the spec. The ` fill `
20
+ appearance displays the form field with a filled background box and an underline, while the
21
+ ` outline ` appearance shows the form field with a border all the way around.
22
+
23
+ The ` legacy ` and ` standard ` appearances implement an older version of the spec where
24
+ ` mat-form-field ` was shown with an underline beneath it. We recommend not using these appearances as
25
+ they do not match the current spec.
26
+
27
+ There are a couple differences in behavior to be aware of between the different appearances.
28
+
29
+ We recommend that text prefix and suffixes in the ` fill ` and ` outline ` appearances only be used in
30
+ conjunction with the ` floatLabel="always" ` option. This is because the resting label and the input
31
+ value do not have the same alignment, and it is therefore impossible to align the prefix or suffix
32
+ in a way that looks good when compared with both. In the ` standard ` and ` legacy ` appearances, the
33
+ resting label and input value align, so this isn't an issue. We plan to improve support for text
34
+ prefix and suffixes in the future so they can be used without ` floatLabel="always" ` .
33
35
34
36
The second important difference is that the ` standard ` , ` fill ` , and ` outline ` appearances do not
35
37
promote placeholders to labels. For the ` legacy ` appearance specifying
36
38
` <input placeholder="placeholder"> ` will result in a floating label being added to the
37
39
` mat-form-field ` . For the newer variants it will just add a normal placeholder to the input. If you
38
- want a floating label, add a ` <mat-label> ` to the ` mat-form-field ` .
40
+ want a floating label, add a ` <mat-label> ` to the ` mat-form-field ` instead.
41
+
42
+ Out of the box, if you do not specify an ` appearance ` for the ` <mat-form-field> ` it will default to
43
+ ` legacy ` . However, this can be configured using a global provider to choose a different default
44
+ appearance for your app.
45
+
46
+ ``` ts
47
+ @NgModule ({
48
+ providers: [
49
+ {provide: MAT_FORM_FIELD_DEFAULT_OPTIONS , useValue: {appearance: ' fill' }}
50
+ ]
51
+ })
52
+ ```
39
53
40
54
<!-- example(form-field-appearance) -->
41
55
42
56
### Floating label
43
57
44
58
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.
59
+ the control does not contain any text or when ` <select matNativeControl> ` does not show any option
60
+ text. By default, when text is present the floating label floats above the form field control. The
61
+ label for a form field can be specified by adding a ` mat-label ` element.
49
62
50
63
In the legacy version of the ` <mat-form-field> ` (one that has no ` appearance ` attribute or has
51
64
` appearance="legacy" ` ) if a label is not specified, the ` placeholder ` attribute on the form control
0 commit comments