Skip to content

Commit b24b9e3

Browse files
authored
feat(material-experimental/mdc-form-field): add support for ac… (#18399)
Previously, we wired up the feature targeting in the theme, but the additional styling for `.mat-accent` and `.mat-warn` were missing. This commit adds styling for the accent and warn palettes. This also fixes an issue where the line-ripple is not displayed.
1 parent 9cfc66d commit b24b9e3

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,14 @@ <h3>&lt;textarea&gt; with bindable autosize </h3>
538538
<mat-card class="demo-card demo-basic">
539539
<mat-toolbar color="primary">Appearance</mat-toolbar>
540540
<mat-card-content>
541-
<mat-form-field appearance="fill">
541+
<mat-form-field appearance="fill" [color]="color">
542542
<mat-label>Fill appearance</mat-label>
543543
<input matInput [(ngModel)]="fillAppearance" required>
544544
<mat-error>This field is required</mat-error>
545545
<mat-hint>Please type something here</mat-hint>
546546
</mat-form-field>
547547

548-
<mat-form-field appearance="outline">
548+
<mat-form-field appearance="outline" [color]="color">
549549
<mat-label>Outline appearance</mat-label>
550550
<input matInput [(ngModel)]="outlineAppearance" required>
551551
<mat-error>This field is required</mat-error>
@@ -554,22 +554,28 @@ <h3>&lt;textarea&gt; with bindable autosize </h3>
554554

555555
<table style="width: 100%" cellspacing="0"><tr>
556556
<td>
557-
<mat-form-field appearance="fill" style="width: 100%">
557+
<mat-form-field appearance="fill" [color]="color" style="width: 100%">
558558
<mat-label>Fill appearance</mat-label>
559559
<input matInput [(ngModel)]="fillAppearance" required>
560560
<mat-error>This field is required</mat-error>
561561
<mat-hint>Please type something here</mat-hint>
562562
</mat-form-field>
563563
</td>
564564
<td>
565-
<mat-form-field appearance="outline" style="width: 100%">
565+
<mat-form-field appearance="outline" [color]="color" style="width: 100%">
566566
<mat-label>Outline appearance</mat-label>
567567
<input matInput [(ngModel)]="outlineAppearance" required>
568568
<mat-error>This field is required</mat-error>
569569
<mat-hint>Please type something here</mat-hint>
570570
</mat-form-field>
571571
</td>
572572
</tr></table>
573+
574+
<mat-button-toggle-group [(ngModel)]="color">
575+
<mat-button-toggle value="primary">Primary</mat-button-toggle>
576+
<mat-button-toggle value="accent">Accent</mat-button-toggle>
577+
<mat-button-toggle value="warn">Warn</mat-button-toggle>
578+
</mat-button-toggle-group>
573579
</mat-card-content>
574580
</mat-card>
575581

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
FloatLabelType,
1313
MatFormFieldAppearance
1414
} from '@angular/material-experimental/mdc-form-field';
15-
import {ErrorStateMatcher} from '@angular/material/core';
15+
import {ErrorStateMatcher, ThemePalette} from '@angular/material/core';
1616

1717
let max = 5;
1818

@@ -25,8 +25,8 @@ const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA
2525
styleUrls: ['mdc-input-demo.css'],
2626
})
2727
export class MdcInputDemo {
28+
color: ThemePalette = 'primary';
2829
floatingLabel: FloatLabelType = 'auto';
29-
color: boolean;
3030
requiredField: boolean;
3131
disableTextarea: boolean;
3232
hideRequiredMarker: boolean;

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,54 @@
11
@use '@material/ripple/mixins' as mdc-ripple;
22

3+
@import '@material/theme/variables.import';
34
@import '@material/textfield/mixins.import';
45
@import '../mdc-helpers/mdc-helpers';
56
@import 'form-field-subscript';
67
@import 'form-field-bottom-line';
78
@import 'mdc-text-field-theme-variable-refresh';
89

10+
// Mixin that overwrites the default MDC text-field color styles to be based on
11+
// the given theme palette. The MDC text-field is styled using `primary` by default.
12+
@mixin _mdc-text-field-color-styles($palette-name, $query: $mat-theme-styles-query) {
13+
$_mdc-text-field-focused-label-color: $mdc-text-field-focused-label-color;
14+
$mdc-text-field-focused-label-color: rgba(mdc-theme-prop-value($palette-name), 0.87) !global;
15+
16+
@include mdc-text-field-caret-color($palette-name, $query);
17+
@include mdc-text-field-line-ripple-color($palette-name, $query);
18+
19+
.mdc-text-field--focused {
20+
@include mdc-text-field-focused_($query);
21+
22+
}
23+
.mdc-text-field--invalid {
24+
@include mdc-text-field-invalid_($query);
25+
}
26+
27+
.mdc-text-field--outlined {
28+
@include mdc-text-field-focused-outline-color($palette-name, $query);
29+
}
30+
31+
$mdc-text-field-focused-label-color: $_mdc-text-field-focused-label-color !global;
32+
}
33+
934
@mixin mat-form-field-theme-mdc($theme) {
1035
@include mat-using-mdc-theme($theme) {
1136
@include _mdc-text-field-refresh-theme-variables() {
1237
@include mdc-text-field-core-styles($query: $mat-theme-styles-query);
1338
@include mdc-floating-label-core-styles($query: $mat-theme-styles-query);
14-
@include mdc-text-field-core-styles($query: $mat-theme-styles-query);
39+
@include mdc-notched-outline-core-styles($query: $mat-base-styles-query);
40+
@include mdc-line-ripple-core-styles($query: $mat-theme-styles-query);
1541
@include _mat-form-field-subscript-theme();
1642
@include _mat-form-field-bottom-line-theme();
1743

44+
.mat-mdc-form-field.mat-accent {
45+
@include _mdc-text-field-color-styles(secondary);
46+
}
47+
48+
.mat-mdc-form-field.mat-warn {
49+
@include _mdc-text-field-color-styles(error);
50+
}
51+
1852
// MDC text-field intends to hide the ripples in the outline appearance. The styles for
1953
// this collide with other styles from the structure styles. This is because the ripples
2054
// are made invisible by using the `mdc-ripple.states-base-color` mixin. The mixin makes the

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,3 @@
5353
min-height: $mdc-text-field-height;
5454
box-sizing: border-box;
5555
}
56-
57-
// In order to make it possible for developers to disable animations for form-fields,
58-
// we only activate the animation styles if animations are not explicitly disabled.
59-
.mat-mdc-form-field:not(.mat-form-field-no-animations) {
60-
@include mdc-notched-outline-core-styles($query: animation);
61-
@include mdc-floating-label-core-styles($query: animation);
62-
@include mdc-text-field-core-styles($query: animation);
63-
@include mdc-line-ripple-core-styles($query: animation);
64-
}

0 commit comments

Comments
 (0)