From debc3a940dd83e66f358084899eac1ca1de47b07 Mon Sep 17 00:00:00 2001 From: Topher Fangio Date: Thu, 10 Sep 2015 14:46:45 -0500 Subject: [PATCH] feat(mdInput): Add support for both labels and placeholders. Previously, if a user supplied both a placeholder and a label, the label would float on top of the placeholder when the input did not have a value. Fix by adding styles/code to support both at the same time. **Note:** If the users provides both a label and a placeholder, the label will no longer animate. Also fix input styles so transition does not happen if input already has a value to avoid unneccessary and eratic-looking animations. Fixes #4462. Fixes #4258. --- .../input/demoBasicUsage/index.html | 2 +- src/components/input/input.js | 76 ++++++++++++------- src/components/input/input.scss | 11 ++- src/components/input/input.spec.js | 55 ++++++++------ 4 files changed, 88 insertions(+), 56 deletions(-) diff --git a/src/components/input/demoBasicUsage/index.html b/src/components/input/demoBasicUsage/index.html index 1852f5c4b44..3f45effd967 100644 --- a/src/components/input/demoBasicUsage/index.html +++ b/src/components/input/demoBasicUsage/index.html @@ -53,7 +53,7 @@ - + diff --git a/src/components/input/input.js b/src/components/input/input.js index 8bab01bf501..a5644846075 100644 --- a/src/components/input/input.js +++ b/src/components/input/input.js @@ -26,8 +26,10 @@ angular.module('material.components.input', [ * Input and textarea elements will not behave properly unless the md-input-container * parent is provided. * - * @param md-is-error {expression=} When the given expression evaluates to true, the input container will go into error state. Defaults to erroring if the input has been touched and is invalid. - * @param md-no-float {boolean=} When present, placeholders will not be converted to floating labels + * @param md-is-error {expression=} When the given expression evaluates to true, the input container + * will go into error state. Defaults to erroring if the input has been touched and is invalid. + * @param md-no-float {boolean=} When present, placeholders will not be converted to floating + * labels. * * @usage * @@ -54,6 +56,7 @@ function mdInputContainerDirective($mdTheming, $parse) { function postLink(scope, element, attr) { $mdTheming(element); } + function ContainerCtrl($scope, $element, $attrs) { var self = this; @@ -69,6 +72,9 @@ function mdInputContainerDirective($mdTheming, $parse) { self.setHasValue = function(hasValue) { $element.toggleClass('md-input-has-value', !!hasValue); }; + self.setHasPlaceholder = function(hasPlaceholder) { + $element.toggleClass('md-input-has-placeholder', !!hasPlaceholder); + }; self.setInvalid = function(isInvalid) { $element.toggleClass('md-input-invalid', !!isInvalid); }; @@ -106,10 +112,15 @@ function labelDirective() { * @description * Use the `` or the `