Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
update(demo): Basic Input demo fix to floating label
Browse files Browse the repository at this point in the history
BREAKING CHANGE: md-input-containers no longer allow both label and placeholder to be used simultaneously. Now the placeholder value (if present) is transcluded as a label or ignored.
When the placeholder value is ignored, a warning will be logged.
  • Loading branch information
ThomasBurleson committed Apr 23, 2015
1 parent 7bd97ac commit d931c0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/input/demoBasicUsage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

<div layout layout-sm="column">
<md-input-container flex>
<label>First Name</label>
<input ng-model="user.firstName" placeholder="Placeholder text">
<label>First name</label>
<input ng-model="user.firstName">
</md-input-container>
<md-input-container flex>
<label>Last Name</label>
Expand Down
12 changes: 8 additions & 4 deletions src/components/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ function mdMaxlengthDirective($animate) {
}
}

function placeholderDirective() {
function placeholderDirective($log) {
return {
restrict: 'A',
require: '^^?mdInputContainer',
Expand All @@ -341,10 +341,14 @@ function placeholderDirective() {
var placeholderText = attr.placeholder;
element.removeAttr('placeholder');

var placeholder = '<label ng-click="delegateClick()">' + placeholderText + '</label>';
if ( inputContainer.element.find('label').length == 0 ) {
var placeholder = '<label ng-click="delegateClick()">' + placeholderText + '</label>';

inputContainer.element.addClass('md-icon-float');
inputContainer.element.prepend(placeholder);
inputContainer.element.addClass('md-icon-float');
inputContainer.element.prepend(placeholder);
} else {
$log.warn("The placeholder='" + placeholderText + "' will be ignored since this md-input-container has a child label element.");
}

}
}
Expand Down

0 comments on commit d931c0d

Please sign in to comment.