Skip to content

Commit

Permalink
fix(autosize): export md-autosize directive (#2432)
Browse files Browse the repository at this point in the history
Closes #2419
  • Loading branch information
devversion authored and kara committed Jan 4, 2017
1 parent 93b0bc9 commit f2d73da
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
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

0 comments on commit f2d73da

Please sign in to comment.