Skip to content

Commit 50af637

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 50af637

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,6 @@ $mat-form-field-default-infix-width: 180px !default;
179179
opacity: 0;
180180
transition: background-color $swift-ease-in-duration $swift-ease-in-timing-function;
181181

182-
.mat-form-field-invalid:not(.mat-focused) & {
183-
height: $mat-form-field-underline-height;
184-
}
185-
186182
.mat-focused &,
187183
.mat-form-field-invalid & {
188184
visibility: visible;
@@ -195,6 +191,17 @@ $mat-form-field-default-infix-width: 180px !default;
195191
}
196192
}
197193

194+
// Note that we need this specific of a selector because we don't want
195+
// the hover effect to show when the user hovers over the hints.
196+
.mat-form-field:not(.mat-form-field-disabled) .mat-input-flex:hover ~ .mat-input-underline {
197+
.mat-form-field-ripple {
198+
visibility: visible;
199+
opacity: 1;
200+
transform: none;
201+
transition: opacity 600ms $swift-ease-out-timing-function;
202+
}
203+
}
204+
198205
// Wrapper for the hints and error messages.
199206
.mat-form-field-subscript-wrapper {
200207
position: absolute;

0 commit comments

Comments
 (0)