This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(textarea): fix textarea grow #5757
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div layout="column" ng-cloak class="md-inline-form" ng-init="textBind = 'Input is binded to a Model'"> | ||
|
||
<md-content layout-padding> | ||
|
||
<div class="demoTextarea"> | ||
<md-input-container class="md-block"> | ||
<label>Fixed Rows</label> | ||
<textarea rows="5" ng-model="textBind">This is an example Content</textarea> | ||
</md-input-container> | ||
</div> | ||
|
||
<div class="demoTextarea"> | ||
<md-input-container class="md-block"> | ||
<label>Minimum Rows</label> | ||
<textarea min-rows="5" ng-model="textBind"></textarea> | ||
</md-input-container> | ||
</div> | ||
|
||
<div class="demoTextarea"> | ||
<md-input-container class="md-block"> | ||
<label>Dynamic Rows</label> | ||
<textarea>This is an example Content</textarea> | ||
</md-input-container> | ||
</div> | ||
|
||
</md-content> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
angular | ||
.module('inputTextareaDemo', ['ngMaterial', 'ngMessages']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.demoTextarea { | ||
margin: 14px; | ||
background-color: #f7f7f7; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,31 +323,36 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) { | |
var node = element[0]; | ||
var container = containerCtrl.element[0]; | ||
|
||
var min_rows = NaN; | ||
var rows = NaN; | ||
var minRows = 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')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a breaking change isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it is. |
||
} else if (node.hasAttribute('min-rows')) { | ||
minRows = parseInt(node.getAttribute('min-rows')); | ||
} | ||
|
||
var onChangeTextarea = $mdUtil.debounce(growTextarea, 1); | ||
var onChangeTextarea = $mdUtil.debounce(function() { | ||
$mdUtil.nextTick(growTextarea); | ||
}, 1); | ||
|
||
function pipelineListener(value) { | ||
onChangeTextarea(); | ||
return value; | ||
} | ||
|
||
if (ngModelCtrl) { | ||
if (hasNgModel) { | ||
ngModelCtrl.$formatters.push(pipelineListener); | ||
ngModelCtrl.$viewChangeListeners.push(pipelineListener); | ||
} else { | ||
onChangeTextarea(); | ||
} | ||
element.on('keydown input', onChangeTextarea); | ||
|
||
if (isNaN(min_rows)) { | ||
element.attr('rows', '1'); | ||
if (isNaN(rows)) { | ||
element.attr('rows', isNaN(minRows) ? '1' : minRows); | ||
|
||
element.on('scroll', onScroll); | ||
} | ||
|
@@ -365,12 +370,13 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) { | |
// temporarily disables element's flex so its height 'runs free' | ||
element.addClass('md-no-flex'); | ||
|
||
if (isNaN(min_rows)) { | ||
var contentHeight; | ||
if (isNaN(rows) || !isNaN(minRows)) { | ||
node.style.height = "auto"; | ||
node.scrollTop = 0; | ||
var height = getHeight(); | ||
if (height) node.style.height = height + 'px'; | ||
} else { | ||
contentHeight = getHeight(); | ||
} | ||
if (!isNaN(rows) || !isNaN(minRows)) { | ||
node.setAttribute("rows", 1); | ||
|
||
if (!lineHeight) { | ||
|
@@ -381,8 +387,22 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) { | |
node.style.minHeight = null; | ||
} | ||
|
||
var rows = Math.min(min_rows, Math.round(node.scrollHeight / lineHeight)); | ||
node.setAttribute("rows", rows); | ||
} | ||
|
||
if (isNaN(rows)) { | ||
if (!isNaN(minRows) && contentHeight) { | ||
var calcHeight; | ||
var minHeight = lineHeight * minRows; | ||
|
||
if (contentHeight <= minHeight) calcHeight = minHeight; | ||
else calcHeight = minHeight + (contentHeight - minHeight); | ||
|
||
node.style.height = calcHeight + "px"; | ||
} else if (contentHeight) { | ||
node.style.height = contentHeight + 'px'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd expect a variable to save the height into and applying |
||
} | ||
} else { | ||
node.style.height = lineHeight * rows + "px"; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layout-padding is making the text areas look weird, wrap them with divs or make a class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied that from the Basic Demo, or is this a difference because of the other inputs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CSS for
layout-padding
changed recently. We are aware of some issues with it, but the quick workaround is to wrap the content in a<div>
.