Skip to content

Commit e91fcb0

Browse files
committed
fix(material-experimental/mdc-form-field): tweak styles to work with MDC
typography
1 parent cab8267 commit e91fcb0

File tree

6 files changed

+36
-35
lines changed

6 files changed

+36
-35
lines changed

src/dev-app/mdc-input/mdc-input-demo.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ <h4>Textarea</h4>
315315
<mat-form-field style="margin-bottom: 4em">
316316
<mat-label>Enter text to count</mat-label>
317317
<textarea matInput #longHint></textarea>
318-
<mat-hint>
319-
Enter some text to count how many characters are in it. The character count is shown on
318+
<mat-hint>Enter
319+
some text to count how many characters are in it. The character count is shown on
320320
the right.
321321
</mat-hint>
322322
<mat-hint align="end" style="white-space: nowrap" aria-live="polite">

src/material-experimental/mdc-form-field/_form-field-subscript.scss

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,34 @@
88
.mat-mdc-form-field-subscript-wrapper {
99
box-sizing: border-box;
1010
width: 100%;
11-
// prevents multi-line errors from overlapping the control.
12-
overflow: hidden;
11+
position: relative;
12+
}
13+
14+
.mat-mdc-form-field-hint-wrapper,
15+
.mat-mdc-form-field-error-wrapper {
16+
position: absolute;
17+
top: 0;
18+
left: 0;
19+
right: 0;
20+
}
21+
22+
.mat-mdc-form-field-bottom-align {
23+
line-height: normal;
24+
}
25+
26+
.mat-mdc-form-field-bottom-align::before {
27+
content: '\200B';
28+
vertical-align: bottom;
1329
}
1430

1531
// Scale down icons in the subscript to be the same size as the text.
16-
.mat-mdc-form-field-subscript-wrapper .mat-icon {
17-
width: 1em;
18-
height: 1em;
19-
font-size: inherit;
20-
vertical-align: baseline;
32+
.mat-mdc-form-field-subscript-wrapper,
33+
.mat-mdc-form-field label {
34+
.mat-icon {
35+
width: 1em;
36+
height: 1em;
37+
font-size: inherit;
38+
}
2139
}
2240

2341
// Clears the floats on the hints. This is necessary for the hint animation to work.
@@ -47,29 +65,11 @@
4765
// helper text in our MDC based form field
4866
@mixin mat-mdc-private-form-field-subscript-typography($config-or-theme) {
4967
$config: mat-get-typography-config($config-or-theme);
50-
// The unit-less line-height from the font config.
51-
$line-height: mat-line-height($config, input);
52-
// The amount to scale the font for the subscript.
53-
$subscript-font-scale: 0.75;
54-
// Font size to use for the subscript text.
55-
$subscript-font-size: $subscript-font-scale * 100%;
56-
// The space between the bottom of the text-field area and the subscript. Mocks in the spec show
57-
// half of the text size, but this margin is applied to an element with the subscript text font
58-
// size, so we need to divide by the scale factor to make it half of the original text size.
59-
$subscript-margin-top: 0.5em / $subscript-font-scale;
60-
// The minimum height applied to the subscript to reserve space for subscript text. This is a
61-
// combination of the subscript's margin and line-height, but we need to multiply by the
62-
// subscript font scale factor since the subscript has a reduced font size.
63-
$subscript-min-height: ($subscript-margin-top + $line-height) * $subscript-font-scale;
64-
// The horizontal padding between the edge of the text box and the start of the subscript text.
65-
$subscript-horizontal-padding: 16px;
6668

6769
// The subscript wrapper has a minimum height to avoid that the form-field
6870
// jumps when hints or errors are displayed.
69-
.mat-mdc-form-field-subscript-wrapper {
70-
min-height: $subscript-min-height;
71-
font-size: $subscript-font-size;
72-
margin-top: $subscript-margin-top;
73-
padding: 0 $subscript-horizontal-padding;
71+
.mat-mdc-form-field-subscript-wrapper,
72+
.mat-mdc-form-field-bottom-align::before {
73+
@include mdc-typography(caption, $query: $mat-typography-styles-query);
7474
}
7575
}

src/material-experimental/mdc-form-field/directives/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const MAT_ERROR = new InjectionToken<MatError>('MatError');
2121
@Directive({
2222
selector: 'mat-error',
2323
host: {
24-
'class': 'mat-mdc-form-field-error',
24+
'class': 'mat-mdc-form-field-error mat-mdc-form-field-bottom-align',
2525
'role': 'alert',
2626
'[id]': 'id',
2727
},

src/material-experimental/mdc-form-field/directives/hint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let nextUniqueId = 0;
1414
@Directive({
1515
selector: 'mat-hint',
1616
host: {
17-
'class': 'mat-mdc-form-field-hint',
17+
'class': 'mat-mdc-form-field-hint mat-mdc-form-field-bottom-align',
1818
'[class.mat-mdc-form-field-hint-end]': 'align === "end"',
1919
'[id]': 'id',
2020
// Remove align attribute to prevent it from interfering with layout.

src/material-experimental/mdc-form-field/form-field.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@
6464
<div matFormFieldLineRipple *ngIf="!_hasOutline()"></div>
6565
</div>
6666

67-
<div class="mat-mdc-form-field-subscript-wrapper"
67+
<div class="mat-mdc-form-field-subscript-wrapper mat-mdc-form-field-bottom-align"
6868
[ngSwitch]="_getDisplayedMessages()">
69-
<div *ngSwitchCase="'error'" [@transitionMessages]="_subscriptAnimationState">
69+
<div class="mat-mdc-form-field-error-wrapper" *ngSwitchCase="'error'"
70+
[@transitionMessages]="_subscriptAnimationState">
7071
<ng-content select="mat-error"></ng-content>
7172
</div>
7273

src/material/form-field/form-field-animations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const matFormFieldAnimations: {
2626
// TODO(mmalerba): Use angular animations for label animation as well.
2727
state('enter', style({ opacity: 1, transform: 'translateY(0%)' })),
2828
transition('void => enter', [
29-
style({ opacity: 0, transform: 'translateY(-100%)' }),
29+
style({ opacity: 0, transform: 'translateY(-5px)' }),
3030
animate('300ms cubic-bezier(0.55, 0, 0.55, 0.2)'),
3131
]),
3232
])

0 commit comments

Comments
 (0)