Skip to content

Commit bc9d25b

Browse files
mmalerbaandrewseguin
authored andcommitted
feat(input): add invalid state styling (#3114)
1 parent 6cdd8db commit bc9d25b

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/lib/input/_input-theme.scss

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
// :focus is applied to the input, but we apply mat-focused to the other elements
2727
// that need to listen to it.
28-
&.mat-focused {
28+
.mat-focused & {
2929
color: $input-floating-placeholder-color;
3030

3131
&.mat-accent {
@@ -43,7 +43,7 @@
4343

4444
// See mat-input-placeholder-floating mixin in input.scss
4545
input.mat-input-element:-webkit-autofill + .mat-input-placeholder,
46-
.mat-input-placeholder.mat-float.mat-focused {
46+
.mat-focused .mat-input-placeholder.mat-float {
4747
.mat-placeholder-required {
4848
color: $input-required-placeholder-color;
4949
}
@@ -63,4 +63,15 @@
6363
}
6464
}
6565
}
66+
67+
.mat-input-container.ng-invalid.ng-touched:not(.mat-focused) {
68+
.mat-input-placeholder,
69+
.mat-placeholder-required {
70+
color: $input-underline-color-warn;
71+
}
72+
73+
.mat-input-underline {
74+
border-color: $input-underline-color-warn;
75+
}
76+
}
6677
}

src/lib/input/input-container.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<label class="mat-input-placeholder"
1313
[attr.for]="_mdInputChild.id"
1414
[class.mat-empty]="_mdInputChild.empty && !_shouldAlwaysFloat"
15-
[class.mat-focused]="_mdInputChild.focused"
1615
[class.mat-float]="_canPlaceholderFloat"
1716
[class.mat-accent]="dividerColor == 'accent'"
1817
[class.mat-warn]="dividerColor == 'warn'"
@@ -33,7 +32,6 @@
3332
<div class="mat-input-underline"
3433
[class.mat-disabled]="_mdInputChild.disabled">
3534
<span class="mat-input-ripple"
36-
[class.mat-focused]="_mdInputChild.focused"
3735
[class.mat-accent]="dividerColor == 'accent'"
3836
[class.mat-warn]="dividerColor == 'warn'"></span>
3937
</div>

src/lib/input/input-container.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ $mat-input-underline-disabled-background-image:
149149
}
150150

151151
// Show the placeholder above the input when it's not empty, or focused.
152-
&.mat-float:not(.mat-empty), &.mat-float.mat-focused {
152+
&.mat-float:not(.mat-empty), .mat-focused &.mat-float {
153153
@include mat-input-placeholder-floating;
154154
}
155155

@@ -207,7 +207,7 @@ $mat-input-underline-disabled-background-image:
207207
transition: transform $swift-ease-out-duration $swift-ease-out-timing-function,
208208
opacity $swift-ease-out-duration $swift-ease-out-timing-function;
209209

210-
&.mat-focused {
210+
.mat-focused & {
211211
opacity: 1;
212212
transform: scaleY(1);
213213
}

src/lib/input/input-container.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ export class MdInputDirective {
235235
templateUrl: 'input-container.html',
236236
styleUrls: ['input-container.css'],
237237
host: {
238-
'[class.mat-input-container]': 'true',
239238
// Remove align attribute to prevent it from interfering with layout.
240239
'[attr.align]': 'null',
240+
'[class.mat-input-container]': 'true',
241+
'[class.mat-focused]': '_mdInputChild.focused',
241242
'[class.ng-untouched]': '_shouldForward("untouched")',
242243
'[class.ng-touched]': '_shouldForward("touched")',
243244
'[class.ng-pristine]': '_shouldForward("pristine")',

0 commit comments

Comments
 (0)