Skip to content

Commit

Permalink
fix(input): add overflow:hidden when calculating autosize height (#5773)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba authored and kara committed Jul 20, 2017
1 parent 23ec30f commit e0fc526
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
21 changes: 21 additions & 0 deletions e2e/components/input-e2e.spec.ts
@@ -1,4 +1,5 @@
import {browser, by, element} from 'protractor';
import {screenshot} from '../screenshot';


describe('input', () => {
Expand Down Expand Up @@ -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');
});
});
});
3 changes: 2 additions & 1 deletion src/demo-app/input/input-demo.html
Expand Up @@ -394,13 +394,14 @@ <h4>Textarea</h4>
<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>
Expand Down
6 changes: 6 additions & 0 deletions src/e2e-app/input/input-e2e.html
Expand Up @@ -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 changes: 3 additions & 0 deletions src/lib/input/autosize.ts
Expand Up @@ -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;
}
Expand Down

0 comments on commit e0fc526

Please sign in to comment.