Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions e2e/components/input-e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to write a unit test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could find some text that previously wasn't calculated right and check that its height is correct now I suppose


// 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