Skip to content

Commit 863bd28

Browse files
committed
refactor all communication between input-container and input into a
separate interface
1 parent a190de7 commit 863bd28

File tree

4 files changed

+116
-80
lines changed

4 files changed

+116
-80
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {Observable} from 'rxjs/Observable';
4040
import {MdOptionSelectionChange, MdOption} from '../core/option/option';
4141
import {ENTER, UP_ARROW, DOWN_ARROW, ESCAPE} from '../core/keyboard/keycodes';
4242
import {Directionality} from '../core/bidi/index';
43-
import {MdInputContainer} from '../input/input-container';
43+
import {MdInputContainer, MdInputDirective} from '../input/input-container';
4444
import {Subscription} from 'rxjs/Subscription';
4545
import {merge} from 'rxjs/observable/merge';
4646
import {fromEvent} from 'rxjs/observable/fromEvent';
@@ -410,8 +410,9 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
410410

411411
// If it's used in a Material container, we should set it through
412412
// the property so it can go through the change detection.
413-
if (this._inputContainer) {
414-
this._inputContainer._mdInputChild.value = inputValue;
413+
if (this._inputContainer &&
414+
this._inputContainer._textFieldControl instanceof MdInputDirective) {
415+
this._inputContainer._textFieldControl.value = inputValue;
415416
} else {
416417
this._element.nativeElement.value = inputValue;
417418
}

src/lib/input/input-container.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99

1010
<span class="mat-input-placeholder-wrapper">
1111
<label class="mat-input-placeholder"
12-
[attr.for]="_mdInputChild.id"
13-
[class.mat-empty]="_mdInputChild.empty && !_shouldAlwaysFloat"
12+
[attr.for]="_textFieldControl.getId()"
13+
[class.mat-empty]="_textFieldControl.isEmpty() && !_shouldAlwaysFloat"
1414
[class.mat-float]="_canPlaceholderFloat"
1515
[class.mat-accent]="color == 'accent'"
1616
[class.mat-warn]="color == 'warn'"
1717
*ngIf="_hasPlaceholder()">
1818
<ng-content select="md-placeholder, mat-placeholder"></ng-content>
19-
{{_mdInputChild.placeholder}}
19+
{{_textFieldControl.getPlaceholder()}}
2020
<span
2121
class="mat-placeholder-required"
2222
aria-hidden="true"
23-
*ngIf="!hideRequiredMarker && _mdInputChild.required">*</span>
23+
*ngIf="!hideRequiredMarker && _textFieldControl.isRequired()">*</span>
2424
</label>
2525
</span>
2626
</div>
@@ -31,7 +31,7 @@
3131
</div>
3232

3333
<div class="mat-input-underline" #underline
34-
[class.mat-disabled]="_mdInputChild.disabled">
34+
[class.mat-disabled]="_textFieldControl.isDisabled()">
3535
<span class="mat-input-ripple"
3636
[class.mat-accent]="color == 'accent'"
3737
[class.mat-warn]="color == 'warn'"></span>

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -644,28 +644,11 @@ describe('MdInputContainer without forms', function () {
644644

645645
// Call the focus handler directly to avoid flakyness where
646646
// browsers don't focus elements if the window is minimized.
647-
input._onFocus();
647+
input._focusChanged(true);
648648
fixture.detectChanges();
649649

650650
expect(container.classList).toContain('mat-focused');
651651
});
652-
653-
it('should not highlight when focusing a readonly input', () => {
654-
let fixture = TestBed.createComponent(MdInputContainerWithReadonlyInput);
655-
fixture.detectChanges();
656-
657-
let input = fixture.debugElement.query(By.directive(MdInputDirective))
658-
.injector.get<MdInputDirective>(MdInputDirective);
659-
let container = fixture.debugElement.query(By.css('md-input-container')).nativeElement;
660-
661-
// Call the focus handler directly to avoid flakyness where
662-
// browsers don't focus elements if the window is minimized.
663-
input._onFocus();
664-
fixture.detectChanges();
665-
666-
expect(input.focused).toBe(false);
667-
expect(container.classList).not.toContain('mat-focused');
668-
});
669652
});
670653

671654
describe('MdInputContainer with forms', () => {

0 commit comments

Comments
 (0)