Skip to content

Commit

Permalink
feat(input): add invalid state styling (#3114)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba authored and andrewseguin committed Feb 17, 2017
1 parent 6cdd8db commit bc9d25b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/lib/input/_input-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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

&.mat-accent {
Expand All @@ -43,7 +43,7 @@

// See mat-input-placeholder-floating mixin in input.scss
input.mat-input-element:-webkit-autofill + .mat-input-placeholder,
.mat-input-placeholder.mat-float.mat-focused {
.mat-focused .mat-input-placeholder.mat-float {
.mat-placeholder-required {
color: $input-required-placeholder-color;
}
Expand All @@ -63,4 +63,15 @@
}
}
}

.mat-input-container.ng-invalid.ng-touched:not(.mat-focused) {
.mat-input-placeholder,
.mat-placeholder-required {
color: $input-underline-color-warn;
}

.mat-input-underline {
border-color: $input-underline-color-warn;
}
}
}
2 changes: 0 additions & 2 deletions src/lib/input/input-container.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<label class="mat-input-placeholder"
[attr.for]="_mdInputChild.id"
[class.mat-empty]="_mdInputChild.empty && !_shouldAlwaysFloat"
[class.mat-focused]="_mdInputChild.focused"
[class.mat-float]="_canPlaceholderFloat"
[class.mat-accent]="dividerColor == 'accent'"
[class.mat-warn]="dividerColor == 'warn'"
Expand All @@ -33,7 +32,6 @@
<div class="mat-input-underline"
[class.mat-disabled]="_mdInputChild.disabled">
<span class="mat-input-ripple"
[class.mat-focused]="_mdInputChild.focused"
[class.mat-accent]="dividerColor == 'accent'"
[class.mat-warn]="dividerColor == 'warn'"></span>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/input/input-container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ $mat-input-underline-disabled-background-image:
}

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

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

&.mat-focused {
.mat-focused & {
opacity: 1;
transform: scaleY(1);
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/input/input-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ export class MdInputDirective {
templateUrl: 'input-container.html',
styleUrls: ['input-container.css'],
host: {
'[class.mat-input-container]': 'true',
// Remove align attribute to prevent it from interfering with layout.
'[attr.align]': 'null',
'[class.mat-input-container]': 'true',
'[class.mat-focused]': '_mdInputChild.focused',
'[class.ng-untouched]': '_shouldForward("untouched")',
'[class.ng-touched]': '_shouldForward("touched")',
'[class.ng-pristine]': '_shouldForward("pristine")',
Expand Down

0 comments on commit bc9d25b

Please sign in to comment.