fix(input): add overflow:hidden when calculating autosize height (#5773)

This commit is contained in:
mmalerba
2017-07-20 10:57:50 -07:00
committed by Kara
parent 23ec30f3a0
commit e0fc5266e8
4 changed files with 32 additions and 1 deletions
+21
View File
@@ -1,4 +1,5 @@
import {browser, by, element} from 'protractor';
import {screenshot} from '../screenshot';
describe('input', () => {
@@ -53,4 +54,24 @@ describe('input', () => {
expect(input.getAttribute('value')).toBe('abc123');
});
});
describe('autosize-textarea', () => {
beforeEach(() => browser.get('/input'));
it('should resize correctly', () => {
let input = element(by.id('autosize-text-area'));
input.sendKeys('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
screenshot('autosize multiple rows');
});
it('should enfore max rows', () => {
let input = element(by.id('autosize-text-area'));
input.sendKeys(
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
screenshot('autosize more than max rows');
});
});
});
+2 -1
View File
@@ -394,13 +394,14 @@
<md-toolbar color="primary">Textarea Autosize</md-toolbar>
<md-card-content>
<h3>Regular &lt;textarea&gt;</h3>
<textarea mdTextareaAutosize class="demo-textarea"></textarea>
<textarea class="demo-textarea" mdTextareaAutosize mdAutosizeMaxRows="10"></textarea>
<h3>&lt;textarea&gt; with md-input-container</h3>
<div>
<md-input-container>
<textarea mdInput
mdTextareaAutosize
mdAutosizeMaxRows="10"
placeholder="Autosized textarea"></textarea>
</md-input-container>
</div>
+6
View File
@@ -14,4 +14,10 @@
<textarea mdInput id="text-area" placeholder="Enter some text"></textarea>
</md-input-container>
</p>
<p>
<md-input-container>
<textarea mdInput mdTextareaAutosize mdAutosizeMaxRows="10" id="autosize-text-area"
placeholder="Enter some text"></textarea>
</md-input-container>
</p>
</section>
+3
View File
@@ -136,10 +136,13 @@ export class MdTextareaAutosize implements AfterViewInit {
}
// Reset the textarea height to auto in order to shrink back to its default size.
// Also temporarily force overflow:hidden, so scroll bars do not interfere with calculations.
textarea.style.height = 'auto';
textarea.style.overflow = 'hidden';
// Use the scrollHeight to know how large the textarea *would* be if fit its entire value.
textarea.style.height = `${textarea.scrollHeight}px`;
textarea.style.overflow = '';
this._previousValue = textarea.value;
}