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

Textarea #559

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ dist
/vendor

.polymer-qp

atlassian-ide-plugin.xml
*.iml
2 changes: 2 additions & 0 deletions src/components/textField/demoBasicUsage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<md-text-float label="Postal Code" ng-model="user.postalCode" > </md-text-float>
</div>
<md-text-float label="Country" ng-model="user.country" disabled > </md-text-float>
<md-text-float label="Intro" ng-model="user.intro" rows="4"
cols="50" type="textarea" > </md-text-float>
</form>
</md-content>

Expand Down
3 changes: 2 additions & 1 deletion src/components/textField/demoBasicUsage/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ angular.module('textFieldDemo1', ['ngMaterial'])
city: "Mountain View" ,
state: "CA" ,
country: "USA" ,
postalCode : "94043"
postalCode : "94043",
intro: ""
};
});

Expand Down
19 changes: 17 additions & 2 deletions src/components/textField/textField.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ angular.module('material.components.textField', [
*
* <!-- Specify an input type if desired. -->
* <md-text-float label="eMail" ng-model="user.email" type="email" ></md-text-float>
*
* <!-- Specify textarea as an input type if desired. -->
* <md-text-float label="intro" ng-model="user.intro" type="textarea" ></md-text-float>
* </hljs>
*/
function mdTextFloatDirective($mdTheming, $mdUtil, $parse) {
Expand Down Expand Up @@ -134,7 +137,14 @@ function mdInputDirective($mdUtil) {
return {
restrict: 'E',
replace: true,
template: '<input >',
template: function createTemplate(element) {
var isTextarea = element.parent().attr('type') === 'textarea';
if (isTextarea) {
return '<textarea >';
} else {
return '<input >';
}
},
require: ['^?mdInputGroup', '?ngModel'],
link: function(scope, element, attr, ctrls) {
if ( !ctrls[0] ) return;
Expand All @@ -146,7 +156,12 @@ function mdInputDirective($mdUtil) {
element.attr('aria-disabled', !!isDisabled);
element.attr('tabindex', !!isDisabled);
});
element.attr('type', attr.type || element.parent().attr('type') || "text");

element.attr({
'type': attr.type || element.parent().attr('type') || "text",
'rows': attr.rows || element.parent().attr('rows'),
'cols': attr.cols || element.parent().attr('cols')
});

// When the input value changes, check if it "has" a value, and
// set the appropriate class on the input group
Expand Down
40 changes: 40 additions & 0 deletions src/components/textField/textField.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,46 @@ describe('Text Field directives', function() {
});
});

describe(' - mdTextFloat type=textarea', function mdTextareaFloatSuit() {
var model;
beforeEach(function () {
model = {
labels: {
intro: 'intro'
},
user: {
filledIntro: 'This is my intro',
emptyIntro: null
}
}
});

it('should configure the amount of collumn and rows', function configureColsAndRows() {
var markup = '<md-text-float rows="4" cols="50"' +
' type="textarea"' +
' label="{{labels.intro}}" ' +
' ng-model="user.filledIntro" >' +
'</md-text-float>';
var el = buildElement(markup, model);
var textarea = el.find('textarea');

expect(textarea.attr('rows')).toBe('4');
expect(textarea.attr('cols')).toBe('50');
});

it('should configure the label', function configureLabel() {
var markup = '<md-text-float rows="4" cols="50"' +
' type="textarea"' +
' label="{{labels.intro}}" ' +
' ng-model="user.filledIntro" >' +
'</md-text-float>';
var el = buildElement(markup, model);
var label = el.find('label');

expect(label.text()).toBe(model.labels.intro);
});
});

// ****************************************************************
// Utility `setup` methods
// ****************************************************************
Expand Down