From db5745bfa23c300214db7df7f38a6e1472061b02 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. Closes #4623. --- .../input/demoBasicUsage/index.html | 2 +- src/components/input/input.js | 74 ++++++++++++------- src/components/input/input.scss | 11 ++- src/components/input/input.spec.js | 55 +++++++------- 4 files changed, 87 insertions(+), 55 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 67fb80b9e75..2f4b158cda1 100644 --- a/src/components/input/input.js +++ b/src/components/input/input.js @@ -27,8 +27,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 * @@ -55,6 +57,7 @@ function mdInputContainerDirective($mdTheming, $parse) { function postLink(scope, element, attr) { $mdTheming(element); } + function ContainerCtrl($scope, $element, $attrs) { var self = this; @@ -73,6 +76,9 @@ function mdInputContainerDirective($mdTheming, $parse) { self.setHasMessages = function(hasMessages) { $element.toggleClass('md-input-has-messages', !!hasMessages); }; + self.setHasPlaceholder = function(hasPlaceholder) { + $element.toggleClass('md-input-has-placeholder', !!hasPlaceholder); + }; self.setInvalid = function(isInvalid) { $element.toggleClass('md-input-invalid', !!isInvalid); }; @@ -110,10 +116,15 @@ function labelDirective() { * @description * Use the `` or the `