Skip to content

Commit e0fc526

Browse files
mmalerbakara
authored andcommitted
fix(input): add overflow:hidden when calculating autosize height (#5773)
1 parent 23ec30f commit e0fc526

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

e2e/components/input-e2e.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {browser, by, element} from 'protractor';
2+
import {screenshot} from '../screenshot';
23

34

45
describe('input', () => {
@@ -53,4 +54,24 @@ describe('input', () => {
5354
expect(input.getAttribute('value')).toBe('abc123');
5455
});
5556
});
57+
58+
describe('autosize-textarea', () => {
59+
beforeEach(() => browser.get('/input'));
60+
61+
it('should resize correctly', () => {
62+
let input = element(by.id('autosize-text-area'));
63+
input.sendKeys('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
64+
screenshot('autosize multiple rows');
65+
});
66+
67+
it('should enfore max rows', () => {
68+
let input = element(by.id('autosize-text-area'));
69+
input.sendKeys(
70+
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +
71+
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +
72+
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +
73+
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
74+
screenshot('autosize more than max rows');
75+
});
76+
});
5677
});

src/demo-app/input/input-demo.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,14 @@ <h4>Textarea</h4>
394394
<md-toolbar color="primary">Textarea Autosize</md-toolbar>
395395
<md-card-content>
396396
<h3>Regular &lt;textarea&gt;</h3>
397-
<textarea mdTextareaAutosize class="demo-textarea"></textarea>
397+
<textarea class="demo-textarea" mdTextareaAutosize mdAutosizeMaxRows="10"></textarea>
398398

399399
<h3>&lt;textarea&gt; with md-input-container</h3>
400400
<div>
401401
<md-input-container>
402402
<textarea mdInput
403403
mdTextareaAutosize
404+
mdAutosizeMaxRows="10"
404405
placeholder="Autosized textarea"></textarea>
405406
</md-input-container>
406407
</div>

src/e2e-app/input/input-e2e.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@
1414
<textarea mdInput id="text-area" placeholder="Enter some text"></textarea>
1515
</md-input-container>
1616
</p>
17+
<p>
18+
<md-input-container>
19+
<textarea mdInput mdTextareaAutosize mdAutosizeMaxRows="10" id="autosize-text-area"
20+
placeholder="Enter some text"></textarea>
21+
</md-input-container>
22+
</p>
1723
</section>

src/lib/input/autosize.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ export class MdTextareaAutosize implements AfterViewInit {
136136
}
137137

138138
// Reset the textarea height to auto in order to shrink back to its default size.
139+
// Also temporarily force overflow:hidden, so scroll bars do not interfere with calculations.
139140
textarea.style.height = 'auto';
141+
textarea.style.overflow = 'hidden';
140142

141143
// Use the scrollHeight to know how large the textarea *would* be if fit its entire value.
142144
textarea.style.height = `${textarea.scrollHeight}px`;
145+
textarea.style.overflow = '';
143146

144147
this._previousValue = textarea.value;
145148
}

0 commit comments

Comments
 (0)