Skip to content

Commit 4ec6a06

Browse files
committed
add a class to form-field depending on the control type for easy styling
1 parent 1a28317 commit 4ec6a06

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

src/lib/form-field/form-field-control.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ export abstract class MdFormFieldControl<T> {
4848
/** Whether the control is in an error state. */
4949
readonly errorState: boolean;
5050

51+
/**
52+
* An optional name for the control type that can be used to distinguish `md-form-field` elements
53+
* based on their control type. The form field will add a class,
54+
* `mat-form-field-type-{{controlType}}` to its root element.
55+
*/
56+
readonly controlType?: string;
57+
5158
/** Sets the list of element IDs that currently describe this control. */
5259
abstract setDescribedByIds(ids: string[]): void;
5360

src/lib/form-field/form-field.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ export class MdFormField implements AfterViewInit, AfterContentInit, AfterConten
159159

160160
ngAfterContentInit() {
161161
this._validateControlChild();
162+
if (this._control.controlType) {
163+
this._elementRef.nativeElement.classList.add(
164+
`mat-form-field-type-${this._control.controlType}`);
165+
}
162166

163167
// Subscribe to changes in the child control state in order to update the form field UI.
164168
startWith.call(this._control.stateChanges, null).subscribe(() => {

src/lib/input/input.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ export class MdInput implements MdFormFieldControl<any>, OnChanges, OnDestroy, D
9292
*/
9393
stateChanges = new Subject<void>();
9494

95+
/** A name for this control that can be used by `md-form-field`. */
96+
controlType = 'mat-input';
97+
9598
/** Whether the element is disabled. */
9699
@Input()
97100
get disabled() { return this.ngControl ? this.ngControl.disabled : this._disabled; }

src/lib/select/select.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ $mat-select-item-height: 3em !default;
8181
height: $mat-select-item-height;
8282
}
8383
}
84+
85+
.mat-form-field-type-mat-select .mat-form-field-flex {
86+
cursor: pointer;
87+
}

src/lib/select/select.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,12 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
284284
*/
285285
stateChanges = new Subject<void>();
286286

287+
/** Whether the select is focused. */
287288
focused = false;
288289

290+
/** A name for this control that can be used by `md-form-field`. */
291+
controlType = 'mat-select';
292+
289293
/** Trigger that opens the select. */
290294
@ViewChild('trigger') trigger: ElementRef;
291295

0 commit comments

Comments
 (0)