Skip to content

fix(autosize): export md-autosize directive #2432

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

Merged
merged 3 commits into from
Jan 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/demo-app/input/input-container-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ <h4>Textarea</h4>
<md-card class="demo-card demo-basic">
<md-toolbar color="primary">Textarea Autosize</md-toolbar>
<md-card-content>
<textarea md-autosize class="demo-textarea"></textarea>
<textarea mdTextareaAutosize class="demo-textarea"></textarea>
<div>
<md-input-container>
<textarea mdInput
md-autosize
mdTextareaAutosize
placeholder="Autosized textarea"></textarea>
</md-input-container>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/demo-app/input/input-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,5 @@ <h4>Textarea</h4>

<md-card>
<h2>textarea autosize</h2>
<textarea md-autosize class="demo-textarea"></textarea>
<textarea mdTextareaAutosize class="demo-textarea"></textarea>
</md-card>
17 changes: 14 additions & 3 deletions src/lib/input/autosize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component} from '@angular/core';
import {Component, ViewChild} from '@angular/core';
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {MdInputModule} from './input';
Expand Down Expand Up @@ -97,6 +97,12 @@ describe('MdTextareaAutosize', () => {
expect(parseInt(textarea.style.maxHeight))
.toBeGreaterThan(previousMaxHeight, 'Expected increased max-height with maxRows increase.');
});

it('should export the mdAutosize reference', () => {
expect(fixture.componentInstance.autosize).toBeTruthy();
expect(fixture.componentInstance.autosize.resizeToFitContent).toBeTruthy();
});

});


Expand All @@ -109,17 +115,22 @@ const textareaStyleReset = `
}`;

@Component({
template: `<textarea md-autosize [minRows]="minRows" [maxRows]="maxRows">{{content}}</textarea>`,
template: `
<textarea mdTextareaAutosize [minRows]="minRows" [maxRows]="maxRows"
#autosize="mdTextareaAutosize">
{{content}}
</textarea>`,
styles: [textareaStyleReset],
})
class AutosizeTextAreaWithContent {
@ViewChild('autosize') autosize: MdTextareaAutosize;
minRows: number = null;
maxRows: number = null;
content: string = '';
}

@Component({
template: `<textarea md-autosize [value]="value"></textarea>`,
template: `<textarea mdTextareaAutosize [value]="value"></textarea>`,
styles: [textareaStyleReset],
})
class AutosizeTextAreaWithValue {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/input/autosize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {Directive, ElementRef, Input, OnInit} from '@angular/core';
* Directive to automatically resize a textarea to fit its content.
*/
@Directive({
selector: 'textarea[md-autosize], textarea[mat-autosize]',
selector: 'textarea[md-autosize], textarea[mat-autosize], textarea[mdTextareaAutosize]',
exportAs: 'mdTextareaAutosize',
host: {
'(input)': 'resizeToFitContent()',
'[style.min-height]': '_minHeight',
Expand Down