Skip to content

Commit ba97a58

Browse files
committed
feat(form-field): implement hover state
[Based on the spec](https://material.io/guidelines/components/text-fields.html#text-fields-states) form fields should have a hover state where the underline gets darkened while the user is hovering and gets replaced by the theme color after the focus the input.
1 parent 3f31171 commit ba97a58

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/lib/form-field/_form-field-theme.scss

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
// Underline colors.
2121
$underline-color: mat-color($foreground, divider, if($is-dark-theme, 0.7, 0.42));
22+
$underline-color-base: mat-color($foreground, divider, if($is-dark-theme, 1, 0.87));
2223
$underline-color-accent: mat-color($accent);
2324
$underline-color-warn: mat-color($warn);
2425
$underline-focused-color: mat-color($primary);
@@ -56,21 +57,27 @@
5657
}
5758

5859
.mat-form-field-ripple {
59-
background-color: $underline-focused-color;
60+
background-color: $underline-color-base;
61+
}
6062

61-
&.mat-accent {
62-
background-color: $underline-color-accent;
63-
}
63+
.mat-form-field.mat-focused {
64+
.mat-form-field-ripple {
65+
background-color: $underline-focused-color;
6466

65-
&.mat-warn {
66-
background-color: $underline-color-warn;
67+
&.mat-accent {
68+
background-color: $underline-color-accent;
69+
}
70+
71+
&.mat-warn {
72+
background-color: $underline-color-warn;
73+
}
6774
}
6875
}
6976

7077
// Styling for the error state of the form field. Note that while the same can be
7178
// achieved with the ng-* classes, we use this approach in order to ensure that the same
7279
// logic is used to style the error state and to show the error messages.
73-
.mat-form-field-invalid {
80+
.mat-form-field.mat-form-field-invalid {
7481
.mat-form-field-label {
7582
color: $underline-color-warn;
7683

src/lib/form-field/form-field.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@ $mat-form-field-default-infix-width: 180px !default;
195195
}
196196
}
197197

198+
// Note that we need this specific of a selector because we don't want
199+
// want the hover effect to show when the user hovers over the hints.
200+
.mat-form-field:not(.mat-form-field-disabled) .mat-input-flex:hover ~ .mat-input-underline {
201+
background: none;
202+
203+
.mat-form-field-ripple {
204+
visibility: visible;
205+
opacity: 1;
206+
transform: none;
207+
transition: none;
208+
}
209+
}
210+
198211
// Wrapper for the hints and error messages.
199212
.mat-form-field-subscript-wrapper {
200213
position: absolute;

0 commit comments

Comments
 (0)