Skip to content

Commit 99c3093

Browse files
author
Ales Rechtorik
committed
rebase + remove autosize
1 parent 3115f7d commit 99c3093

File tree

2 files changed

+2
-121
lines changed

2 files changed

+2
-121
lines changed

src/lib/input/input.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
[autofocus]="autofocus"
5454
[disabled]="disabled"
5555
[id]="inputId"
56-
[mdAutosize]="autosize"
5756
[attr.maxlength]="maxlength"
5857
[attr.minlength]="minlength"
5958
[readonly]="readonly"

src/lib/input/input.ts

Lines changed: 2 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -89,124 +89,6 @@ export class MdHint {
8989
@Input() align: 'start' | 'end' = 'start';
9090
}
9191

92-
/**
93-
* Enables auto expanding behaviour for the textarea
94-
* based on: https://github.com/stevepapa/angular2-autosize
95-
*/
96-
@Directive({
97-
selector: 'textarea[mdAutosize]'
98-
})
99-
export class MdAutosize implements OnInit {
100-
// public because of AOT
101-
@HostListener('input')
102-
public _onChange() {
103-
if (this._isActive) {
104-
this._adjust();
105-
}
106-
}
107-
108-
// public because of AOT
109-
@Input('mdAutosize')
110-
public _isActive: boolean;
111-
112-
// public because of AOT
113-
// TODO: change to a setter, to recalculate on change
114-
@Input('attr.rows')
115-
public _rows: string;
116-
117-
private _height: number;
118-
private _lineHeight: number;
119-
120-
constructor(private _elRef: ElementRef) {}
121-
122-
ngOnInit() {
123-
if (this._isActive) {
124-
this._elRef.nativeElement.style.overflow = 'hidden';
125-
126-
// check is rows is explicitly set, otherwise we don't need to
127-
// care about it(and getting the actual line-height) at all
128-
if (this._rows) {
129-
this._lineHeight = this._getLineHeight();
130-
this._elRef.nativeElement.style.minHeight = `${+this._rows * this._lineHeight}px`;
131-
}
132-
133-
this._adjust();
134-
}
135-
}
136-
137-
private _adjust() {
138-
// reset height(and rows if it was set by the user)
139-
// to the default values to properly calculate new height
140-
this._elRef.nativeElement.style.height = 'auto';
141-
142-
// only need to do this if user explicitly set rows
143-
if (this._rows) {
144-
this._elRef.nativeElement.rows = this._rows;
145-
}
146-
147-
this._height = +this._elRef.nativeElement.scrollHeight;
148-
149-
// only need to do this if user explicitly set rows
150-
if (this._rows) {
151-
this._elRef.nativeElement.rows = this._getCalculatedRows();
152-
}
153-
154-
this._elRef.nativeElement.style.height = `${this._height}px`;
155-
}
156-
157-
private _getCalculatedRows() {
158-
return Math.round(this._height / this._lineHeight);
159-
}
160-
161-
private _getLineHeight(): number {
162-
const el: HTMLTextAreaElement = this._elRef.nativeElement;
163-
164-
// get the actual computed styles for the element
165-
const computedStyles = window.getComputedStyle(el);
166-
167-
// if line height is explicitly set(to a pixel value), use that
168-
if (computedStyles.lineHeight && computedStyles.lineHeight.toLowerCase().indexOf('px') >= 0) {
169-
// return stripped of the "px" and as a number
170-
return parseFloat(computedStyles.lineHeight);
171-
}
172-
173-
// create temporary element
174-
const tempEl = <HTMLTextAreaElement>document.createElement(el.nodeName);
175-
176-
// reset styling, visually hiden the element
177-
// and set its font styles to match the ones of our textarea
178-
tempEl.setAttribute('rows', '1');
179-
tempEl.setAttribute(
180-
'style',
181-
`
182-
margin: 0px;
183-
padding: 0px;
184-
visibility: hidden;
185-
opacity: 0;
186-
font-family: ${computedStyles.fontFamily};
187-
font-size: ${computedStyles.fontSize};
188-
`
189-
);
190-
191-
// fill in one row
192-
tempEl.value = '-';
193-
194-
// append to parent element to correctly inherit same values
195-
// as the actual textarea
196-
el.parentNode.appendChild(tempEl);
197-
198-
// get the actual line height
199-
const lineHeight = tempEl.clientHeight;
200-
201-
// cleanup
202-
tempEl.parentNode.removeChild(tempEl);
203-
204-
return lineHeight;
205-
}
206-
}
207-
208-
209-
21092
/**
21193
* Component that represents a text input. It encapsulates the <input> HTMLElement and
21294
* improve on its behaviour, along with styling it according to the Material Design.
@@ -477,9 +359,9 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
477359

478360

479361
@NgModule({
480-
declarations: [MdPlaceholder, MdInput, MdHint, MdAutosize],
362+
declarations: [MdPlaceholder, MdInput, MdHint],
481363
imports: [CommonModule, FormsModule],
482-
exports: [MdPlaceholder, MdInput, MdHint, MdAutosize],
364+
exports: [MdPlaceholder, MdInput, MdHint],
483365
})
484366
export class MdInputModule {
485367
static forRoot(): ModuleWithProviders {

0 commit comments

Comments
 (0)