Skip to content

Commit 2a1ef5a

Browse files
committed
comments, round 1
1 parent 4a5f035 commit 2a1ef5a

File tree

9 files changed

+40
-38
lines changed

9 files changed

+40
-38
lines changed

src/demo-app/input/input-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</tr></table>
1313
<p>
1414
<textarea md-textarea class="demo-full-width" placeholder="Address" value="1600 Amphitheatre Pkway"></textarea>
15-
<textarea md-textarea class="demo-full-width" placeholder="Address 2"></textarea>
15+
<textarea md-textarea md-autosize class="demo-full-width" placeholder="Address 2"></textarea>
1616
</p>
1717
</form>
1818
</md-card-content>

src/lib/input/autosize.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component} from '@angular/core';
22
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
33
import {By} from '@angular/platform-browser';
4-
import {MdInputModule} from './input';
4+
import {MdInputModule} from './index';
55
import {MdTextareaAutosize} from './autosize';
66

77

src/lib/input/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {ModuleWithProviders, NgModule} from '@angular/core';
33

44
import {ProjectionModule, PortalModule} from '../core';
55

6+
import {MdTextareaAutosize} from './autosize';
67
import {MdInput} from './input';
78
import {MdPlaceholder, MdPlaceholderContent} from './placeholder';
89

@@ -12,9 +13,9 @@ export * from './placeholder';
1213

1314

1415
@NgModule({
15-
declarations: [MdPlaceholderContent, MdPlaceholder, MdInput],
16+
declarations: [MdPlaceholderContent, MdPlaceholder, MdInput, MdTextareaAutosize],
1617
imports: [PortalModule, ProjectionModule, CommonModule],
17-
exports: [MdPlaceholder, MdInput],
18+
exports: [MdPlaceholder, MdInput, MdTextareaAutosize],
1819
entryComponents: [MdPlaceholderContent]
1920
})
2021
export class MdInputModule {

src/lib/input/input.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div (click)="focus()"
2-
[class]="_cssClass"
2+
class="md-input-wrapper"
3+
[ngClass]="_cssClass"
34
[attr.style]="_safeCssStyle"
4-
[class.md-end]="align == 'end'"
5-
[class.md-input-wrapper]="true">
5+
[class.md-end]="align == 'end'">
66
<div class="md-input-table">
77
<div class="md-input-prefix"><template [ngTemplateOutlet]="_prefixTemplate()"></template></div>
88
<template #prefix>{{mdPrefix}}</template>

src/lib/input/input.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ $md-input-underline-disabled-background-image:
5757
}
5858

5959
// The Input element proper.
60-
input[md-input], textarea[md-textarea] {
60+
.md-input-element {
6161
// Font needs to be inherited, because by default <input> has a system font.
6262
font: inherit;
6363

src/lib/input/input.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ describe('MdInput', function () {
5555
fixture.detectChanges();
5656

5757
let el = fixture.debugElement.query(By.directive(MdInput)).nativeElement;
58-
expect(el.getAttribute('class')).toBeNull();
58+
// We set the input element's class.
59+
expect(el.getAttribute('class')).toBe('md-input-element');
5960
expect(el.getAttribute('style')).toBeNull();
6061
}));
6162

src/lib/input/input.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {
22
Component,
3+
ElementRef,
34
HostBinding,
5+
HostListener,
46
Input,
5-
ViewChild,
6-
ElementRef,
77
OnInit,
8+
TemplateRef,
9+
ViewChild,
810
ViewEncapsulation,
9-
HostListener,
10-
TemplateRef, forwardRef,
11+
forwardRef,
1112
} from '@angular/core';
1213
import {DomSanitizer, SafeStyle} from '@angular/platform-browser';
1314
import {
@@ -16,8 +17,7 @@ import {
1617
MdError,
1718
coerceBooleanProperty
1819
} from '../core';
19-
import {MdTextareaAutosize} from './autosize';
20-
import {MD_PLACEHOLDER_HOST_TOKEN, MdPlaceholderHost} from './placeholder';
20+
import {MD_PLACEHOLDER_HOST, MdPlaceholderHost} from './placeholder';
2121
import {PortalHost} from '../core/portal/portal';
2222
import {PortalHostDirective} from '../core/portal/portal-directives';
2323

@@ -47,7 +47,7 @@ const MD_INPUT_INVALID_INPUT_TYPE = [
4747
styleUrls: ['input.css'],
4848
encapsulation: ViewEncapsulation.None,
4949
providers: [
50-
{ provide: MD_PLACEHOLDER_HOST_TOKEN, useExisting: forwardRef(() => MdInput) }
50+
{ provide: MD_PLACEHOLDER_HOST, useExisting: forwardRef(() => MdInput) }
5151
],
5252
host: {
5353
// This is to remove the properties of the `input md-input` itself. We still want to use them
@@ -70,7 +70,7 @@ export class MdInput implements OnInit, MdPlaceholderHost {
7070
get _safeCssStyle(): SafeStyle {
7171
return this._dom.bypassSecurityTrustStyle(this._cssStyle || '');
7272
}
73-
@HostBinding('attr.class') get _attrClass(): any { return null; }
73+
@HostBinding('attr.class') get _attrClass(): any { return 'md-input-element'; }
7474
@HostBinding('attr.style') get _attrStyle(): any { return null; }
7575

7676
@Input('type') _type: string;
@@ -138,18 +138,3 @@ export class MdInput implements OnInit, MdPlaceholderHost {
138138
this._ref.nativeElement.focus();
139139
}
140140
}
141-
142-
143-
@NgModule({
144-
declarations: [MdPlaceholder, MdInput, MdHint, MdTextareaAutosize],
145-
imports: [CommonModule, FormsModule],
146-
exports: [MdPlaceholder, MdInput, MdHint, MdTextareaAutosize],
147-
})
148-
export class MdInputModule {
149-
static forRoot(): ModuleWithProviders {
150-
return {
151-
ngModule: MdInputModule,
152-
providers: []
153-
};
154-
}
155-
}

src/lib/input/placeholder.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {By} from '@angular/platform-browser';
88
import {MdInputModule} from './index';
99
import {ProjectionModule} from '../core/projection/projection';
1010

11-
fdescribe('MdPlaceholder', function () {
11+
describe('MdPlaceholder', function () {
1212
beforeEach(async(() => {
1313
TestBed.configureTestingModule({
1414
imports: [MdInputModule.forRoot(), FormsModule, ProjectionModule.forRoot()],
@@ -45,6 +45,8 @@ fdescribe('MdPlaceholder', function () {
4545
let labelEl: HTMLLabelElement = el.querySelector('label');
4646
expect(labelEl).not.toBeNull();
4747
expect(labelEl.innerText).toEqual('template placeholder');
48+
expect(labelEl.querySelector('b')).not.toBeNull();
49+
expect(labelEl.querySelector('b').innerText).toEqual('placeholder');
4850

4951
instance.required = true;
5052
fixture.detectChanges();
@@ -59,7 +61,7 @@ class MdPlaceholderStringTestController {
5961

6062
@Component({template: `
6163
<input md-input [required]="required" [placeholder]="p">
62-
<template #p>template placeholder</template>
64+
<template #p>template <b>placeholder</b></template>
6365
`})
6466
class MdPlaceholderTemplateTestController {
6567
required: boolean = false;

src/lib/input/placeholder.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
import {
2+
Component,
3+
ComponentRef,
24
Directive,
5+
HostBinding,
6+
HostListener,
37
Inject,
48
Input,
59
OpaqueToken,
6-
TemplateRef, Component, ViewContainerRef, ComponentRef, HostBinding, ViewChild, HostListener,
7-
AfterContentInit, ReflectiveInjector, Injector,
10+
TemplateRef,
11+
ViewChild,
12+
ViewContainerRef,
813
} from '@angular/core';
914
import {PortalHost} from '../core';
1015
import {ComponentPortal} from '../core/portal/portal';
1116
import {coerceBooleanProperty} from '../core/coersion/boolean-property';
1217

1318

14-
export const MD_PLACEHOLDER_HOST_TOKEN = new OpaqueToken('mdPlaceholderHost');
19+
/**
20+
* A token to provide the host interface that MdPlaceholder will use to inject itself in
21+
* the View tree. If this token isn't on the host of the directive, an error will be thrown.
22+
* @type {OpaqueToken}
23+
*/
24+
export const MD_PLACEHOLDER_HOST = new OpaqueToken('mdPlaceholderHost');
1525

26+
/**
27+
* Interface for components that want to host an MdPlaceholder directive.
28+
*/
1629
export interface MdPlaceholderHost {
1730
placeholderPortalHost: PortalHost;
1831
readonly dividerColor: string;
@@ -68,7 +81,7 @@ export class MdPlaceholder {
6881
_required: boolean = false;
6982
_floatingPlaceholder: boolean = true;
7083

71-
constructor(@Inject(MD_PLACEHOLDER_HOST_TOKEN) public _host: MdPlaceholderHost,
84+
constructor(@Inject(MD_PLACEHOLDER_HOST) public _host: MdPlaceholderHost,
7285
private _vcr: ViewContainerRef) {}
7386

7487
ngOnInit() {

0 commit comments

Comments
 (0)