Skip to content
Merged
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ You can set the initial line number using `rows` attribute:
```html
<textarea autogrow rows="1"></textarea>
```


### Autogrow on css properties change

You can define which CSS properties have to be watched in order to trigger the auto-growing:
```html
<textarea autogrow="font-family,font-size"></textarea>
```
23 changes: 23 additions & 0 deletions angularjs-autogrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@

$scope.$watch($attrs.ngModel, $scope.autogrowFn);

// Extract css properties to spy on
var spyProps = $attrs.autogrow ? $attrs.autogrow.split(',') : [];
angular.forEach(spyProps, function(property) {
// Set a watcher on each property
$scope.$watch(
function() {
return $element.css(property);
},
styleChangedCallBack
);
});

/**
*
* @param newValue
* @param oldValue
*/
function styleChangedCallBack(newValue, oldValue) {
if (newValue !== oldValue) {
$scope.autogrowFn();
}
}

/**
* Auto-resize when there's content on page load
*/
Expand Down
2 changes: 1 addition & 1 deletion angularjs-autogrow.min.js
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angularjs-autogrow",
"version": "0.3.1",
"version": "0.4.0",
"description": "AngularJS 1.x directive for auto-grow / auto-resize of textarea elements",
"main": "angularjs-autogrow.js",
"scripts": {
Expand Down