Skip to content

Commit 0754320

Browse files
authored
refactor(input): rename input-container to form-field... (#6331)
* refactor all communication between input-container and input into a separate interface * rename input-container to form-field * alias mat-input-* classes with mat-form-field-* classes * separate md-form-field into separate directory * rebase and fix lint * address comments * addressed comments * getter methods --> readonly properties
1 parent 5ccf25d commit 0754320

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1377
-1166
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.mat-input-container {
1+
.mat-form-field {
22
width: 250px;
33
}

src/demo-app/autocomplete/autocomplete-demo.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
margin: 24px;
88
}
99

10-
.mat-input-container {
10+
.mat-form-field {
1111
margin-top: 16px;
1212
}
1313
}

src/demo-app/datepicker/datepicker-demo.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ <h2>Options</h2>
99
<md-input-container>
1010
<input mdInput [mdDatepicker]="minDatePicker" [(ngModel)]="minDate" placeholder="Min date">
1111
<md-datepicker-toggle mdSuffix [for]="minDatePicker"></md-datepicker-toggle>
12+
<md-datepicker #minDatePicker [touchUi]="touch" [disabled]="datepickerDisabled"></md-datepicker>
1213
</md-input-container>
13-
<md-datepicker #minDatePicker [touchUi]="touch" [disabled]="datepickerDisabled"></md-datepicker>
1414
<md-input-container>
1515
<input mdInput [mdDatepicker]="maxDatePicker" [(ngModel)]="maxDate" placeholder="Max date">
1616
<md-datepicker-toggle mdSuffix [for]="maxDatePicker"></md-datepicker-toggle>
17+
<md-datepicker #maxDatePicker [touchUi]="touch" [disabled]="datepickerDisabled"></md-datepicker>
1718
</md-input-container>
18-
<md-datepicker #maxDatePicker [touchUi]="touch" [disabled]="datepickerDisabled"></md-datepicker>
1919
</p>
2020
<p>
2121
<md-input-container>
2222
<input mdInput [mdDatepicker]="startAtPicker" [(ngModel)]="startAt" placeholder="Start at date">
2323
<md-datepicker-toggle mdSuffix [for]="startAtPicker"></md-datepicker-toggle>
24+
<md-datepicker #startAtPicker [touchUi]="touch" [disabled]="datepickerDisabled"></md-datepicker>
2425
</md-input-container>
25-
<md-datepicker #startAtPicker [touchUi]="touch" [disabled]="datepickerDisabled"></md-datepicker>
2626
</p>
2727

2828
<h2>Result</h2>
@@ -40,20 +40,20 @@ <h2>Result</h2>
4040
placeholder="Pick a date"
4141
(dateInput)="onDateInput($event)"
4242
(dateChange)="onDateChange($event)">
43+
<md-datepicker
44+
#resultPicker
45+
[touchUi]="touch"
46+
[disabled]="datepickerDisabled"
47+
[startAt]="startAt"
48+
[startView]="yearView ? 'year' : 'month'">
49+
</md-datepicker>
4350
<md-error *ngIf="resultPickerModel.hasError('mdDatepickerParse')">
4451
"{{resultPickerModel.getError('mdDatepickerParse').text}}" is not a valid date!
4552
</md-error>
4653
<md-error *ngIf="resultPickerModel.hasError('mdDatepickerMin')">Too early!</md-error>
4754
<md-error *ngIf="resultPickerModel.hasError('mdDatepickerMax')">Too late!</md-error>
4855
<md-error *ngIf="resultPickerModel.hasError('mdDatepickerFilter')">Date unavailable!</md-error>
4956
</md-input-container>
50-
<md-datepicker
51-
#resultPicker
52-
[touchUi]="touch"
53-
[disabled]="datepickerDisabled"
54-
[startAt]="startAt"
55-
[startView]="yearView ? 'year' : 'month'">
56-
</md-datepicker>
5757
</p>
5858
<p>Last input: {{lastDateInput}}</p>
5959
<p>Last change: {{lastDateChange}}</p>
@@ -83,9 +83,9 @@ <h2>Input disabled datepicker</h2>
8383
<input mdInput [mdDatepicker]="datePicker1" [(ngModel)]="date" [min]="minDate" [max]="maxDate"
8484
[mdDatepickerFilter]="filterOdd ? dateFilter : null" [disabled]="true"
8585
placeholder="Input disabled">
86-
</md-input-container>
87-
<md-datepicker #datePicker1 [touchUi]="touch" [startAt]="startAt"
86+
<md-datepicker #datePicker1 [touchUi]="touch" [startAt]="startAt"
8887
[startView]="yearView ? 'year' : 'month'"></md-datepicker>
88+
</md-input-container>
8989
</p>
9090

9191
<h2>Input disabled, datepicker popup enabled</h2>
@@ -95,7 +95,7 @@ <h2>Input disabled, datepicker popup enabled</h2>
9595
<input mdInput disabled [mdDatepicker]="datePicker2" [(ngModel)]="date" [min]="minDate"
9696
[max]="maxDate" [mdDatepickerFilter]="filterOdd ? dateFilter : null"
9797
placeholder="Input disabled, datepicker enabled">
98+
<md-datepicker #datePicker2 [touchUi]="touch" [disabled]="false" [startAt]="startAt"
99+
[startView]="yearView ? 'year' : 'month'"></md-datepicker>
98100
</md-input-container>
99-
<md-datepicker #datePicker2 [touchUi]="touch" [disabled]="false" [startAt]="startAt"
100-
[startView]="yearView ? 'year' : 'month'"></md-datepicker>
101101
</p>

src/demo-app/demo-material-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
MdDatepickerModule,
1212
MdDialogModule,
1313
MdExpansionModule,
14+
MdFormFieldModule,
1415
MdGridListModule,
1516
MdIconModule,
1617
MdInputModule,
@@ -50,6 +51,7 @@ import {CdkTableModule} from '@angular/cdk/table';
5051
MdDatepickerModule,
5152
MdDialogModule,
5253
MdExpansionModule,
54+
MdFormFieldModule,
5355
MdGridListModule,
5456
MdIconModule,
5557
MdInputModule,

src/demo-app/tabs/tabs-demo.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tabs-demo .mat-card {
4343
margin-top: 8px;
4444
}
4545

46-
.mat-input-container {
46+
.mat-form-field {
4747
width: 100px;
4848
}
4949

src/e2e-app/e2e-app-module.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,24 @@ import {InputE2E} from './input/input-e2e';
2020
import {SidenavE2E} from './sidenav/sidenav-e2e';
2121
import {BlockScrollStrategyE2E} from './block-scroll-strategy/block-scroll-strategy-e2e';
2222
import {
23-
OverlayContainer, FullscreenOverlayContainer, MdGridListModule, MdProgressBarModule,
24-
MdProgressSpinnerModule, MdTabsModule, MdRadioModule, MdSlideToggleModule, MdMenuModule,
25-
MdListModule, MdInputModule, MdIconModule, MdDialogModule, MdCheckboxModule, MdButtonModule,
26-
MdSidenavModule, MdNativeDateModule,
23+
FullscreenOverlayContainer,
24+
MdButtonModule,
25+
MdCheckboxModule,
26+
MdDialogModule,
27+
MdFormFieldModule,
28+
MdGridListModule,
29+
MdIconModule,
30+
MdInputModule,
31+
MdListModule,
32+
MdMenuModule,
33+
MdNativeDateModule,
34+
MdProgressBarModule,
35+
MdProgressSpinnerModule,
36+
MdRadioModule,
37+
MdSidenavModule,
38+
MdSlideToggleModule,
39+
MdTabsModule,
40+
OverlayContainer,
2741
} from '@angular/material';
2842
import {ExampleModule} from '@angular/material-examples';
2943

@@ -35,6 +49,7 @@ import {ExampleModule} from '@angular/material-examples';
3549
MdButtonModule,
3650
MdCheckboxModule,
3751
MdDialogModule,
52+
MdFormFieldModule,
3853
MdGridListModule,
3954
MdIconModule,
4055
MdInputModule,

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 12 additions & 12 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 {MdFormField} from '../form-field/index';
4444
import {Subscription} from 'rxjs/Subscription';
4545
import {merge} from 'rxjs/observable/merge';
4646
import {fromEvent} from 'rxjs/observable/fromEvent';
@@ -153,7 +153,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
153153
private _changeDetectorRef: ChangeDetectorRef,
154154
@Inject(MD_AUTOCOMPLETE_SCROLL_STRATEGY) private _scrollStrategy,
155155
@Optional() private _dir: Directionality,
156-
@Optional() @Host() private _inputContainer: MdInputContainer,
156+
@Optional() @Host() private _formField: MdFormField,
157157
@Optional() @Inject(DOCUMENT) private _document: any) {}
158158

159159
ngOnDestroy() {
@@ -246,8 +246,8 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
246246
fromEvent(this._document, 'touchend')
247247
)).call(filter, (event: MouseEvent | TouchEvent) => {
248248
const clickTarget = event.target as HTMLElement;
249-
const inputContainer = this._inputContainer ?
250-
this._inputContainer._elementRef.nativeElement : null;
249+
const inputContainer = this._formField ?
250+
this._formField._elementRef.nativeElement : null;
251251

252252
return this._panelOpen &&
253253
clickTarget !== this._element.nativeElement &&
@@ -329,16 +329,16 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
329329
* This method manually floats the placeholder until the panel can be closed.
330330
*/
331331
private _floatPlaceholder(): void {
332-
if (this._inputContainer && this._inputContainer.floatPlaceholder === 'auto') {
333-
this._inputContainer.floatPlaceholder = 'always';
332+
if (this._formField && this._formField.floatPlaceholder === 'auto') {
333+
this._formField.floatPlaceholder = 'always';
334334
this._manuallyFloatingPlaceholder = true;
335335
}
336336
}
337337

338338
/** If the placeholder has been manually elevated, return it to its normal state. */
339339
private _resetPlaceholder(): void {
340340
if (this._manuallyFloatingPlaceholder) {
341-
this._inputContainer.floatPlaceholder = 'auto';
341+
this._formField.floatPlaceholder = 'auto';
342342
this._manuallyFloatingPlaceholder = false;
343343
}
344344
}
@@ -408,10 +408,10 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
408408
// The display value can also be the number zero and shouldn't fall back to an empty string.
409409
const inputValue = toDisplay != null ? toDisplay : '';
410410

411-
// If it's used in a Material container, we should set it through
412-
// the property so it can go through the change detection.
413-
if (this._inputContainer) {
414-
this._inputContainer._mdInputChild.value = inputValue;
411+
// If it's used within a `MdFormField`, we should set it through the property so it can go
412+
// through change detection.
413+
if (this._formField) {
414+
this._formField._control.value = inputValue;
415415
} else {
416416
this._element.nativeElement.value = inputValue;
417417
}
@@ -469,7 +469,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
469469
}
470470

471471
private _getConnectedElement(): ElementRef {
472-
return this._inputContainer ? this._inputContainer._connectionContainerRef : this._element;
472+
return this._formField ? this._formField._connectionContainerRef : this._element;
473473
}
474474

475475
/** Returns the width of the input element, so the panel width can match it. */

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {Directionality, Direction} from '../core/bidi/index';
2323
import {Subscription} from 'rxjs/Subscription';
2424
import {ENTER, DOWN_ARROW, SPACE, UP_ARROW, ESCAPE} from '../core/keyboard/keycodes';
2525
import {MdOption} from '../core/option/option';
26-
import {MdInputContainer} from '../input/input-container';
26+
import {MdFormField, MdFormFieldModule} from '../form-field/index';
2727
import {Observable} from 'rxjs/Observable';
2828
import {Subject} from 'rxjs/Subject';
2929
import {createKeyboardEvent, dispatchFakeEvent, typeInElement} from '@angular/cdk/testing';
@@ -41,6 +41,7 @@ describe('MdAutocomplete', () => {
4141
TestBed.configureTestingModule({
4242
imports: [
4343
MdAutocompleteModule,
44+
MdFormFieldModule,
4445
MdInputModule,
4546
FormsModule,
4647
ReactiveFormsModule,
@@ -517,7 +518,7 @@ describe('MdAutocomplete', () => {
517518

518519
it('should disable input in view when disabled programmatically', () => {
519520
const inputUnderline =
520-
fixture.debugElement.query(By.css('.mat-input-underline')).nativeElement;
521+
fixture.debugElement.query(By.css('.mat-form-field-underline')).nativeElement;
521522

522523
expect(input.disabled)
523524
.toBe(false, `Expected input to start out enabled in view.`);
@@ -1319,10 +1320,10 @@ describe('MdAutocomplete', () => {
13191320
fixture.detectChanges();
13201321

13211322
const input = fixture.nativeElement.querySelector('input');
1322-
const placeholder = fixture.nativeElement.querySelector('.mat-input-placeholder');
1323+
const placeholder = fixture.nativeElement.querySelector('.mat-form-field-placeholder');
13231324

13241325
expect(input.value).toBe('California');
1325-
expect(placeholder.classList).not.toContain('mat-empty');
1326+
expect(placeholder.classList).not.toContain('mat-form-field-empty');
13261327
}));
13271328

13281329
});
@@ -1417,7 +1418,7 @@ class SimpleAutocomplete implements OnDestroy {
14171418

14181419
@ViewChild(MdAutocompleteTrigger) trigger: MdAutocompleteTrigger;
14191420
@ViewChild(MdAutocomplete) panel: MdAutocomplete;
1420-
@ViewChild(MdInputContainer) inputContainer: MdInputContainer;
1421+
@ViewChild(MdFormField) inputContainer: MdFormField;
14211422
@ViewChildren(MdOption) options: QueryList<MdOption>;
14221423

14231424
states = [

src/lib/chips/chip-list.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {createKeyboardEvent} from '@angular/cdk/testing';
99
import {MdInputModule} from '../input/index';
1010
import {LEFT_ARROW, RIGHT_ARROW, BACKSPACE, DELETE, TAB} from '../core/keyboard/keycodes';
1111
import {Directionality} from '../core';
12+
import {MdFormFieldModule} from '../form-field/index';
1213

1314
describe('MdChipList', () => {
1415
let fixture: ComponentFixture<any>;
@@ -23,7 +24,7 @@ describe('MdChipList', () => {
2324

2425
beforeEach(async(() => {
2526
TestBed.configureTestingModule({
26-
imports: [MdChipsModule, MdInputModule, NoopAnimationsModule],
27+
imports: [MdChipsModule, MdFormFieldModule, MdInputModule, NoopAnimationsModule],
2728
declarations: [
2829
StandardChipList, InputContainerChipList
2930
],

src/lib/chips/chips.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $mat-chips-chip-margin: 8px;
3232
}
3333
}
3434

35-
.mat-input-prefix & {
35+
.mat-form-field-prefix & {
3636
&:last-child {
3737
margin-right: $mat-chips-chip-margin;
3838
}
@@ -76,7 +76,7 @@ $mat-chips-chip-margin: 8px;
7676
}
7777
}
7878

79-
.mat-input-prefix .mat-chip-list-wrapper {
79+
.mat-form-field-prefix .mat-chip-list-wrapper {
8080
margin-bottom: $mat-chips-chip-margin;
8181
}
8282

src/lib/core/compatibility/compatibility.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export const MAT_ELEMENTS_SELECTOR = `
7575
mat-hint,
7676
mat-icon,
7777
mat-input-container,
78+
mat-form-field,
7879
mat-list,
7980
mat-list-item,
8081
mat-menu,
@@ -151,6 +152,7 @@ export const MD_ELEMENTS_SELECTOR = `
151152
md-hint,
152153
md-icon,
153154
md-input-container,
155+
md-form-field,
154156
md-list,
155157
md-list-item,
156158
md-menu,

src/lib/core/theming/_all-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
@import '../../toolbar/toolbar-theme';
2828
@import '../../tooltip/tooltip-theme';
2929
@import '../../snack-bar/simple-snack-bar-theme';
30+
@import '../../form-field/form-field-theme';
3031

3132

3233
// Create a theme.
@@ -42,6 +43,7 @@
4243
@include mat-datepicker-theme($theme);
4344
@include mat-dialog-theme($theme);
4445
@include mat-expansion-panel-theme($theme);
46+
@include mat-form-field-theme($theme);
4547
@include mat-grid-list-theme($theme);
4648
@include mat-icon-theme($theme);
4749
@include mat-input-theme($theme);

src/lib/core/typography/_all-typography.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
@import '../../snack-bar/simple-snack-bar-theme';
2929
@import '../option/option-theme';
3030
@import '../option/optgroup-theme';
31+
@import '../../form-field/form-field-theme';
3132

3233

3334
// Includes all of the typographic styles.
@@ -47,6 +48,7 @@
4748
@include mat-datepicker-typography($config);
4849
@include mat-dialog-typography($config);
4950
@include mat-expansion-panel-typography($config);
51+
@include mat-form-field-typography($config);
5052
@include mat-grid-list-typography($config);
5153
@include mat-icon-typography($config);
5254
@include mat-input-typography($config);

src/lib/datepicker/datepicker-input.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
Validators
3232
} from '@angular/forms';
3333
import {Subscription} from 'rxjs/Subscription';
34-
import {MdInputContainer} from '../input/input-container';
34+
import {MdFormField} from '../form-field/index';
3535
import {DOWN_ARROW} from '../core/keyboard/keycodes';
3636
import {DateAdapter} from '../core/datetime/index';
3737
import {createMissingDateImplError} from './datepicker-errors';
@@ -212,7 +212,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
212212
private _renderer: Renderer2,
213213
@Optional() private _dateAdapter: DateAdapter<D>,
214214
@Optional() @Inject(MD_DATE_FORMATS) private _dateFormats: MdDateFormats,
215-
@Optional() private _mdInputContainer: MdInputContainer) {
215+
@Optional() private _mdInputContainer: MdFormField) {
216216
if (!this._dateAdapter) {
217217
throw createMissingDateImplError('DateAdapter');
218218
}

0 commit comments

Comments
 (0)