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

Commit b9a57aa

Browse files
crisbetoThomasBurleson
authored andcommitted
feat(textarea): add the ability to trigger a resize manually
Adds support for manually resizing a textarea via the `md-resize-textarea` scope event. This useful for cases where the textarea might not have gotten the proper height, because it's inside an element that's being animated. Fixes #8376. Closes #8657
1 parent d3cb371 commit b9a57aa

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/components/input/input.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ function labelDirective() {
269269
* - If a `textarea` has the `rows` attribute, it will treat the `rows` as the minimum height and will
270270
* continue growing as the user types. For example a textarea with `rows="3"` will be 3 lines of text
271271
* high initially. If no rows are specified, the directive defaults to 1.
272+
* - The textarea's height gets set on initialization, as well as while the user is typing. In certain situations
273+
* (e.g. while animating) the directive might have been initialized, before the element got it's final height. In
274+
* those cases, you can trigger a resize manually by broadcasting a `md-resize-textarea` event on the scope.
272275
* - If you wan't a `textarea` to stop growing at a certain point, you can specify the `max-rows` attribute.
273276
* - The textarea's bottom border acts as a handle which users can drag, in order to resize the element vertically.
274277
* Once the user has resized a `textarea`, the autogrowing functionality becomes disabled. If you don't want a
@@ -405,6 +408,7 @@ function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout, $mdGesture)
405408
// so rows attribute will take precedence if present
406409
var minRows = attr.hasOwnProperty('rows') ? parseInt(attr.rows) : NaN;
407410
var maxRows = attr.hasOwnProperty('maxRows') ? parseInt(attr.maxRows) : NaN;
411+
var scopeResizeListener = scope.$on('md-resize-textarea', growTextarea);
408412
var lineHeight = null;
409413
var node = element[0];
410414

@@ -488,6 +492,7 @@ function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout, $mdGesture)
488492

489493
isAutogrowing = false;
490494
angular.element($window).off('resize', growTextarea);
495+
scopeResizeListener && scopeResizeListener();
491496
element
492497
.attr('md-no-autogrow', '')
493498
.off('input', growTextarea);

0 commit comments

Comments
 (0)