Skip to content

Commit 236942c

Browse files
authored
Merge pull request #40 from karptonite/patch-onlygrow
Fix onlyGrow so that it takes precedence over maxRows consistently
2 parents cb4fe28 + a9d286b commit 236942c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

projects/autosize/src/lib/autosize.directive.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ export class AutosizeDirective implements OnDestroy, OnChanges, AfterContentChec
148148
height += parseInt(computedStyle.getPropertyValue('border-top-width'));
149149
height += parseInt(computedStyle.getPropertyValue('border-bottom-width'));
150150

151-
const willGrow = height > this.textAreaEl.offsetHeight;
151+
const oldHeight = this.textAreaEl.offsetHeight;
152+
const willGrow = height > oldHeight;
152153

153154
if (this.onlyGrow === false || willGrow) {
154155
const lineHeight = this._getLineHeight();
@@ -158,7 +159,9 @@ export class AutosizeDirective implements OnDestroy, OnChanges, AfterContentChec
158159
height = this._minRows * lineHeight;
159160

160161
} else if (this.maxRows && this.maxRows <= rowsCount) {
161-
height = this.maxRows * lineHeight;
162+
// never shrink the textarea if onlyGrow is true
163+
const maxHeight = this.maxRows * lineHeight;
164+
height = this.onlyGrow ? Math.max(maxHeight, oldHeight): maxHeight;
162165
this.textAreaEl.style.overflow = 'auto';
163166

164167
} else {

0 commit comments

Comments
 (0)