Skip to content

Commit 42fffb2

Browse files
committed
Address feedback
1 parent 7615b21 commit 42fffb2

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/lib/input/autosize.spec.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,26 +185,14 @@ describe('MatTextareaAutosize', () => {
185185
autosize = fixtureWithPlaceholder.debugElement.query(
186186
By.directive(MatTextareaAutosize)).injector.get<MatTextareaAutosize>(MatTextareaAutosize);
187187

188-
// To be able to trigger a new calculation of the height with a long placeholder, the textarea
189-
// value needs to be changed.
190-
textarea.value = '1';
191-
autosize.resizeToFitContent();
192-
193-
textarea.value = '';
194-
autosize.resizeToFitContent();
188+
triggerTextareaResize();
195189

196190
const heightWithLongPlaceholder = textarea.clientHeight;
197191

198192
fixtureWithPlaceholder.componentInstance.placeholder = 'Short';
199193
fixtureWithPlaceholder.detectChanges();
200194

201-
// To be able to trigger a new calculation of the height with a short placeholder, the
202-
// textarea value needs to be changed.
203-
textarea.value = '1';
204-
autosize.resizeToFitContent();
205-
206-
textarea.value = '';
207-
autosize.resizeToFitContent();
195+
triggerTextareaResize();
208196

209197
expect(textarea.clientHeight).toBe(heightWithLongPlaceholder,
210198
'Expected the textarea height to be the same with a long placeholder.');
@@ -261,8 +249,18 @@ describe('MatTextareaAutosize', () => {
261249
textarea = fixtureWithForms.nativeElement.querySelector('textarea');
262250
expect(textarea.getBoundingClientRect().height).toBeGreaterThan(1);
263251
});
264-
});
265252

253+
/** Triggers a textarea resize to fit the content. */
254+
function triggerTextareaResize() {
255+
// To be able to trigger a new calculation of the height with a short placeholder, the
256+
// textarea value needs to be changed.
257+
textarea.value = '1';
258+
autosize.resizeToFitContent();
259+
260+
textarea.value = '';
261+
autosize.resizeToFitContent();
262+
}
263+
});
266264

267265
// Styles to reset padding and border to make measurement comparisons easier.
268266
const textareaStyleReset = `

src/lib/input/autosize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class MatTextareaAutosize implements AfterViewInit, DoCheck {
150150
return;
151151
}
152152

153-
const previousPlaceholder = textarea.placeholder;
153+
const placeholderText = textarea.placeholder;
154154

155155
// Reset the textarea height to auto in order to shrink back to its default size.
156156
// Also temporarily force overflow:hidden, so scroll bars do not interfere with calculations.
@@ -164,7 +164,7 @@ export class MatTextareaAutosize implements AfterViewInit, DoCheck {
164164
// Use the scrollHeight to know how large the textarea *would* be if fit its entire value.
165165
textarea.style.height = `${textarea.scrollHeight}px`;
166166
textarea.style.overflow = '';
167-
textarea.placeholder = previousPlaceholder;
167+
textarea.placeholder = placeholderText;
168168

169169
this._previousValue = value;
170170
}

0 commit comments

Comments
 (0)