Skip to content

Commit 4bdfcb0

Browse files
committed
addressed some comments
1 parent d7814ae commit 4bdfcb0

File tree

4 files changed

+47
-51
lines changed

4 files changed

+47
-51
lines changed

src/lib/input/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './autosize'
22
export * from './input';
33
export * from './input-wrapper';
4+
export * from './input-wrapper-errors';

src/lib/input/input-wrapper-errors.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {MdError} from '../core/errors/error';
2+
3+
4+
export class MdInputWrapperPlaceholderConflictError extends MdError {
5+
constructor() {
6+
super('Placeholder attribute and child element were both specified.');
7+
}
8+
}
9+
10+
11+
export class MdInputWrapperUnsupportedTypeError extends MdError {
12+
constructor(type: string) {
13+
super(`Input type "${type}" isn't supported by md-input-wrapper.`);
14+
}
15+
}
16+
17+
18+
export class MdInputWrapperDuplicatedHintError extends MdError {
19+
constructor(align: string) {
20+
super(`A hint was already declared for 'align="${align}"'.`);
21+
}
22+
}

src/lib/input/input-wrapper.spec.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {async, TestBed, ComponentFixture, inject} from '@angular/core/testing';
1+
import {async, TestBed, inject} from '@angular/core/testing';
22
import {Component} from '@angular/core';
33
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
44
import {By} from '@angular/platform-browser';
@@ -218,12 +218,10 @@ describe('MdInputWrapper', function () {
218218
fixture.componentInstance.placeholder = 'Other placeholder';
219219
fixture.detectChanges();
220220

221-
waitForMutationObserver(fixture, () => {
222-
el = fixture.debugElement.query(By.css('label'));
223-
expect(el).not.toBeNull();
224-
expect(el.nativeElement.textContent).toMatch('Other placeholder');
225-
expect(el.nativeElement.textContent).not.toMatch(/\*/g);
226-
});
221+
el = fixture.debugElement.query(By.css('label'));
222+
expect(el).not.toBeNull();
223+
expect(el.nativeElement.textContent).toMatch('Other placeholder');
224+
expect(el.nativeElement.textContent).not.toMatch(/\*/g);
227225
}));
228226

229227
it('supports placeholder element', async(() => {
@@ -237,12 +235,10 @@ describe('MdInputWrapper', function () {
237235
fixture.componentInstance.placeholder = 'Other placeholder';
238236
fixture.detectChanges();
239237

240-
waitForMutationObserver(fixture, () => {
241-
el = fixture.debugElement.query(By.css('label'));
242-
expect(el).not.toBeNull();
243-
expect(el.nativeElement.textContent).toMatch('Other placeholder');
244-
expect(el.nativeElement.textContent).not.toMatch(/\*/g);
245-
});
238+
el = fixture.debugElement.query(By.css('label'));
239+
expect(el).not.toBeNull();
240+
expect(el.nativeElement.textContent).toMatch('Other placeholder');
241+
expect(el.nativeElement.textContent).not.toMatch(/\*/g);
246242
}));
247243

248244
it('supports placeholder required star', () => {
@@ -263,9 +259,7 @@ describe('MdInputWrapper', function () {
263259

264260
fixture.componentInstance.disabled = true;
265261
fixture.detectChanges();
266-
waitForMutationObserver(fixture, () => {
267-
expect(underlineEl.classList.contains('md-disabled')).toBe(true, 'should be disabled');
268-
});
262+
expect(underlineEl.classList.contains('md-disabled')).toBe(true, 'should be disabled');
269263
}));
270264

271265
it('supports textarea', () => {
@@ -409,10 +403,3 @@ class MdTextareaWithBindings {
409403
cols: number = 8;
410404
wrap: string = 'hard';
411405
}
412-
413-
function waitForMutationObserver<T>(fixture: ComponentFixture<T>, f: () => void) {
414-
setTimeout(() => {
415-
fixture.detectChanges();
416-
f();
417-
}, 0);
418-
}

src/lib/input/input-wrapper.ts

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ import {
1010
ViewEncapsulation,
1111
Optional,
1212
Output,
13-
EventEmitter
13+
EventEmitter,
14+
Renderer
1415
} from '@angular/core';
15-
import {MdError, coerceBooleanProperty} from '../core';
16+
import {coerceBooleanProperty} from '../core';
1617
import {NgModel} from '@angular/forms';
1718
import {MdFeatureDetector} from '../core/platform/feature-detector';
19+
import {
20+
MdInputWrapperUnsupportedTypeError,
21+
MdInputWrapperPlaceholderConflictError,
22+
MdInputWrapperDuplicatedHintError
23+
} from './input-wrapper-errors';
1824

1925

2026
// Invalid input type. Using one of these will throw an MdInputWrapperUnsupportedTypeError.
@@ -35,27 +41,6 @@ const MD_INPUT_INVALID_TYPES = [
3541
let nextUniqueId = 0;
3642

3743

38-
export class MdInputWrapperPlaceholderConflictError extends MdError {
39-
constructor() {
40-
super('Placeholder attribute and child element were both specified.');
41-
}
42-
}
43-
44-
45-
export class MdInputWrapperUnsupportedTypeError extends MdError {
46-
constructor(type: string) {
47-
super(`Input type "${type}" isn't supported by md-input-wrapper.`);
48-
}
49-
}
50-
51-
52-
export class MdInputWrapperDuplicatedHintError extends MdError {
53-
constructor(align: string) {
54-
super(`A hint was already declared for 'align="${align}"'.`);
55-
}
56-
}
57-
58-
5944
/**
6045
* The placeholder directive. The content can declare this to implement more
6146
* complex placeholders.
@@ -107,7 +92,7 @@ export class MdInputDirective implements AfterContentInit {
10792
set placeholder(value: string) {
10893
if (this._placeholder != value) {
10994
this._placeholder = value;
110-
this.placeholderChange.emit(this._placeholder);
95+
this._placeholderChange.emit(this._placeholder);
11196
}
11297
}
11398
private _placeholder = '';
@@ -125,10 +110,10 @@ export class MdInputDirective implements AfterContentInit {
125110
}
126111
private _type = 'text';
127112

128-
@Input()
129113
value: any;
130114

131-
@Output() placeholderChange = new EventEmitter<string>();
115+
/** Emits an event when the placeholder changes so that the `md-input-wrapper` can re-validate. */
116+
@Output() _placeholderChange = new EventEmitter<string>();
132117

133118
get empty() { return (this.value == null || this.value == '') && !this._isNeverEmpty(); }
134119

@@ -148,6 +133,7 @@ export class MdInputDirective implements AfterContentInit {
148133

149134
constructor(private _featureDetector: MdFeatureDetector,
150135
private _elementRef: ElementRef,
136+
private _renderer: Renderer,
151137
@Optional() private _ngModel: NgModel) {
152138
// Force setter to be called in case id was not specified.
153139
this.id = this.id;
@@ -164,7 +150,7 @@ export class MdInputDirective implements AfterContentInit {
164150
}
165151

166152
/** Focus the input element. */
167-
focus() { this._elementRef.nativeElement.focus(); }
153+
focus() { this._renderer.invokeElementMethod(this._elementRef.nativeElement, 'focus'); }
168154

169155
/** Make sure the input is a supported type. */
170156
private _validateType() {
@@ -231,7 +217,7 @@ export class MdInputWrapper implements AfterContentInit {
231217
this._hintChildren.changes.subscribe(() => {
232218
this._validateHints();
233219
});
234-
this._mdInputChild.placeholderChange.subscribe(() => {
220+
this._mdInputChild._placeholderChange.subscribe(() => {
235221
this._validatePlaceholders();
236222
});
237223
}

0 commit comments

Comments
 (0)