Skip to content

Commit

Permalink
fix(textarea): fix textarea grow
Browse files Browse the repository at this point in the history
100% perfect fix for textarea, check it out

Fixes angular#5751
  • Loading branch information
devversion committed Nov 16, 2015
1 parent 9d52697 commit d807b8f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/components/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) {
var node = element[0];
var container = containerCtrl.element[0];

var min_rows = NaN;
var rows = NaN;
var lineHeight = null;
// can't check if height was or not explicity set,
// so rows attribute will take precedence if present
if (node.hasAttribute('rows')) {
min_rows = parseInt(node.getAttribute('rows'));
rows = parseInt(node.getAttribute('rows'));
}

var onChangeTextarea = $mdUtil.debounce(growTextarea, 1);
Expand All @@ -287,7 +287,7 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) {
}
element.on('keydown input', onChangeTextarea);

if (isNaN(min_rows)) {
if (isNaN(rows)) {
element.attr('rows', '1');

element.on('scroll', onScroll);
Expand All @@ -306,7 +306,7 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) {
// temporarily disables element's flex so its height 'runs free'
element.addClass('md-no-flex');

if (isNaN(min_rows)) {
if (isNaN(rows)) {
node.style.height = "auto";
node.scrollTop = 0;
var height = getHeight();
Expand All @@ -322,7 +322,6 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) {
node.style.minHeight = null;
}

var rows = Math.min(min_rows, Math.round(node.scrollHeight / lineHeight));
node.setAttribute("rows", rows);
node.style.height = lineHeight * rows + "px";
}
Expand Down

0 comments on commit d807b8f

Please sign in to comment.