Skip to content

Commit aea79f0

Browse files
authored
fix(material-experimental/mdc-form-field): setup typography styles for form-fields (#18480)
Currently the MDC-based form-field does not have any typography styles. MDC only sets typography styles on the inputs and textarea elements. This won't work for our form-field since we support custom form-field controls. To make this work, the input/textarea elements inherit the font styles from parent elements, but we need to set up the typography styles for the containing `mat-form-field` element.
1 parent 6329ce7 commit aea79f0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/material-experimental/mdc-form-field/_mdc-form-field.scss

+4
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@
5959
@include mdc-notched-outline-core-styles($query: $mat-typography-styles-query);
6060
@include mdc-line-ripple-core-styles($query: $mat-typography-styles-query);
6161
@include _mat-form-field-subscript-typography($config);
62+
63+
.mat-mdc-form-field {
64+
@include mat-typography-level-to-styles($config, input);
65+
}
6266
}
6367
}

src/material-experimental/mdc-form-field/_mdc-text-field-structure-overrides.scss

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
// Unset the border set by MDC. We move the border (which serves as the Material Design
2020
// text-field bottom line) into its own element. This is necessary because we want the
21-
// bottom-line to span across the whole form-field (including prefixes and suffixes).
22-
// Also we want to ensure that font styles are inherited for input elements. We want input
23-
// text to align with surrounding text. Also font inheritance has been enabled in the non
24-
// MDC-based implementation of the form-field too, so we need it for backwards compatibility.
21+
// bottom-line to span across the whole form-field (including prefixes and suffixes). Also
22+
// we ensure that font styles are inherited for input elements. We do this because inputs by
23+
// default have explicit font styles from the user agent, and we set the desired font styles
24+
// in the parent `mat-form-field` element (for better custom form-field control support).
2525
.mat-mdc-input-element {
2626
font: inherit;
2727
border: none;

0 commit comments

Comments
 (0)