Skip to content

Commit 95e6bab

Browse files
author
Ales Rechtorik
committed
address comments, add tests
1 parent 4784301 commit 95e6bab

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

src/lib/input/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,8 @@ export class MyComponent implements OnInit {
108108

109109
## Textareas
110110

111-
Supports same attributes as MdInput, except `type`, additionally it support `autosize` attribute
112-
which enables auto expanding functionality.
113-
114111
```html
115-
<md-textarea autosize placeholder="Textarea with autosize"></md-textarea>
112+
<md-textarea placeholder="Textarea with autosize"></md-textarea>
116113
```
117114

118115
### Example

src/lib/input/input.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ md-input, md-textarea {
9595
}
9696
}
9797

98-
.md-input-element-textarea {
99-
min-height: 60px;
100-
}
101-
10298
// The placeholder label. This is invisible unless it is. The logic to show it is
10399
// basically `empty || (float && (!empty || focused))`. Float is dependent on the
104100
// `floatingPlaceholder` input.

src/lib/input/input.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe('MdInput', function () {
5757
MdInputTextTestController,
5858
MdInputPasswordTestController,
5959
MdInputNumberTestController,
60+
MdTextareaWithBindings,
6061
],
6162
});
6263

@@ -619,6 +620,20 @@ describe('MdInput', function () {
619620

620621
expect(inputElement.name).toBe('some-name');
621622
});
623+
624+
describe('md-textarea', () => {
625+
it('supports the rows, cols, and wrap attributes', () => {
626+
let fixture = TestBed.createComponent(MdTextareaWithBindings);
627+
628+
fixture.detectChanges();
629+
630+
const textarea: HTMLTextAreaElement = fixture.nativeElement.querySelector('textarea');
631+
expect(textarea.rows).toBe(4);
632+
expect(textarea.cols).toBe(8);
633+
expect(textarea.wrap).toBe('hard');
634+
});
635+
});
636+
622637
});
623638

624639
@Component({template: `<md-input id="test-id"></md-input>`})
@@ -791,3 +806,11 @@ class MdInputPasswordTestController {
791806
class MdInputNumberTestController {
792807
placeholder: string = '';
793808
}
809+
810+
@Component({template:
811+
`<md-textarea [rows]="rows" [cols]="cols" [wrap]="wrap" placeholder="Snacks"></md-textarea>`})
812+
class MdTextareaWithBindings {
813+
rows: number = 4;
814+
cols: number = 8;
815+
wrap: string = 'hard';
816+
}

src/lib/input/input.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
167167
@Input() type: string = 'text';
168168
@Input() name: string = null;
169169

170+
// textarea-specific
171+
@Input() rows: number = null;
172+
@Input() cols: number = null;
173+
@Input() wrap: string = null;
174+
170175
private _floatingPlaceholder: boolean = true;
171176
private _autofocus: boolean = false;
172177
private _disabled: boolean = false;
@@ -229,9 +234,14 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
229234

230235
@ViewChild('input') _inputElement: ElementRef;
231236

232-
public elementType: 'input' | 'textarea' = undefined;
237+
elementType: 'input' | 'textarea';
233238

234-
constructor(private _elRef: ElementRef) { }
239+
constructor(public _elementRef: ElementRef) {
240+
// Set the element type depending on normalized selector used(md-input / md-textarea)
241+
this.elementType = this._elementRef.nativeElement.nodeName.toLowerCase() === 'md-input' ?
242+
'input' :
243+
'textarea';
244+
}
235245

236246
/** Set focus on input */
237247
focus() {
@@ -286,13 +296,6 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
286296
ngAfterContentInit() {
287297
this._validateConstraints();
288298

289-
// Set the element type depending on normalized selector used(md-input / md-textarea)
290-
if (this._elRef.nativeElement.tagName.toLowerCase() === 'md-input') {
291-
this.elementType = 'input';
292-
} else {
293-
this.elementType = 'textarea';
294-
}
295-
296299
// Trigger validation when the hint children change.
297300
this._hintChildren.changes.subscribe(() => {
298301
this._validateConstraints();

0 commit comments

Comments
 (0)