Skip to content

Commit 8c9dce4

Browse files
committed
add a class to form-field depending on the control type for easy styling
1 parent b35e35c commit 8c9dce4

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
@@ -167,6 +167,10 @@ export class MdFormField implements AfterViewInit, AfterContentInit, AfterConten
167167

168168
ngAfterContentInit() {
169169
this._validateControlChild();
170+
if (this._control.controlType) {
171+
this._elementRef.nativeElement.classList.add(
172+
`mat-form-field-type-${this._control.controlType}`);
173+
}
170174

171175
// Subscribe to changes in the child control state in order to update the form field UI.
172176
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
@@ -298,8 +298,12 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
298298
*/
299299
stateChanges = new Subject<void>();
300300

301+
/** Whether the select is focused. */
301302
focused = false;
302303

304+
/** A name for this control that can be used by `md-form-field`. */
305+
controlType = 'mat-select';
306+
303307
/** Trigger that opens the select. */
304308
@ViewChild('trigger') trigger: ElementRef;
305309

0 commit comments

Comments
 (0)