Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Multiline input #565

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
5 changes: 5 additions & 0 deletions src/components/textField/_textField.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ md-input-group,
input, textarea {
background: none;
}

textarea {
resize: none;
overflow: hidden;
}
}

// Light-Theme
Expand Down
27 changes: 26 additions & 1 deletion src/components/textField/textField.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ function mdInputDirective($mdUtil) {
return {
restrict: 'E',
replace: true,
template: '<input >',
template: function(element, attr){
isTextarea = element.parent().attr('type') == "multiline";

if (isTextarea)
return '<textarea rows="1"></textarea>'
else
return '<input>'
},
require: ['^?mdInputGroup', '?ngModel'],
link: function(scope, element, attr, ctrls) {
var inputGroupCtrl = ctrls[0];
Expand Down Expand Up @@ -180,6 +187,24 @@ function mdInputDirective($mdUtil) {
inputGroupCtrl.setHasValue(false);
});

element.on('scroll', function(e){
var textarea = e.target;
textarea.scrollTop = 0;

// for smooth new line adding
var line = textarea.scrollHeight - textarea.offsetHeight;
height = textarea.offsetHeight + line;
textarea.style.height = height;
});

element.on('keyup', function(e){
var textarea = e.target;
textarea.style.height = "auto";
var line = textarea.scrollHeight - textarea.offsetHeight;
textarea.scrollTop = 0;
height = textarea.offsetHeight + (line > 0 ? line : 0);
textarea.style.height = height;
});

function isNotEmpty(value) {
value = angular.isUndefined(value) ? element.val() : value;
Expand Down