Skip to content

Commit

Permalink
Merge pull request #8 from the-software-factory/MH-2619
Browse files Browse the repository at this point in the history
Added autogrow on css properties change
  • Loading branch information
evyros authored Jul 7, 2017
2 parents 0b48e7b + f6f64fb commit dd1985d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
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

0 comments on commit dd1985d

Please sign in to comment.