Skip to content

Commit f98c567

Browse files
committed
finish up MdFormFieldControl implementation
1 parent 6853f4d commit f98c567

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/lib/select/_select-theme.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@
5252
&.mat-accent {
5353
@include _mat-select-inner-content-theme($accent);
5454
}
55+
56+
&.mat-warn,
57+
&.mat-select-invalid {
58+
@include _mat-select-inner-content-theme($warn);
59+
}
5560
}
5661

57-
.mat-select:focus:not(.mat-select-disabled).mat-warn, .mat-select-invalid {
62+
.mat-select.mat-select-invalid:not(.mat-select-disabled) {
5863
@include _mat-select-inner-content-theme($warn);
5964
}
6065
}

src/lib/select/select.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,13 @@ export class MdSelectTrigger {}
164164
'[attr.aria-invalid]': 'errorState',
165165
'[attr.aria-owns]': '_optionIds',
166166
'[attr.aria-multiselectable]': 'multiple',
167+
'[attr.aria-describedby]': '_ariaDescribedby || null',
167168
'[class.mat-select-disabled]': 'disabled',
168169
'[class.mat-select-invalid]': 'errorState',
169170
'[class.mat-select-required]': 'required',
170171
'class': 'mat-select',
171172
'(keydown)': '_handleClosedKeydown($event)',
173+
'(focus)': '_onFocus()',
172174
'(blur)': '_onBlur()',
173175
},
174176
animations: [
@@ -213,6 +215,9 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
213215
/** The cached height of the trigger element. */
214216
private _triggerHeight: number;
215217

218+
/** The aria-describedby attribute on the select for improved a11y. */
219+
_ariaDescribedby: string;
220+
216221
/** The cached font-size of the trigger element. */
217222
_triggerFontSize = 0;
218223

@@ -281,12 +286,8 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
281286
*/
282287
stateChanges = new Subject<void>();
283288

284-
/** Whether the select is focused. TODO(mmalerba): Implement for real. */
285289
focused = false;
286290

287-
/** TODO(mmalerba): Implement for real. */
288-
setDescribedByIds(x: string[]) {return x}
289-
290291
/** Trigger that opens the select. */
291292
@ViewChild('trigger') trigger: ElementRef;
292293

@@ -313,6 +314,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
313314
get placeholder() { return this._placeholder; }
314315
set placeholder(value: string) {
315316
this._placeholder = value;
317+
this.stateChanges.next();
316318

317319
// Must wait to record the trigger width to ensure placeholder width is included.
318320
Promise.resolve(null).then(() => this._setTriggerWidth());
@@ -321,7 +323,10 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
321323
/** Whether the component is required. */
322324
@Input()
323325
get required() { return this._required; }
324-
set required(value: any) { this._required = coerceBooleanProperty(value); }
326+
set required(value: any) {
327+
this._required = coerceBooleanProperty(value);
328+
this.stateChanges.next();
329+
}
325330

326331
/** Whether the user should be allowed to select multiple options. */
327332
@Input()
@@ -349,6 +354,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
349354
set value(newValue: any) {
350355
this.writeValue(newValue);
351356
this._value = newValue;
357+
this.stateChanges.next();
352358
}
353359
private _value: any;
354360

@@ -370,7 +376,10 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
370376
/** Unique id of the element. */
371377
@Input()
372378
get id() { return this._id; }
373-
set id(value: string) { this._id = value || this._uid; }
379+
set id(value: string) {
380+
this._id = value || this._uid;
381+
this.stateChanges.next();
382+
}
374383
private _id: string;
375384

376385
/** Combined stream of all of the child options' change events. */
@@ -521,6 +530,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
521530
setDisabledState(isDisabled: boolean): void {
522531
this.disabled = isDisabled;
523532
this._changeDetectorRef.markForCheck();
533+
this.stateChanges.next();
524534
}
525535

526536
/** Whether or not the overlay panel is open. */
@@ -613,14 +623,23 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
613623
this._changeDetectorRef.markForCheck();
614624
}
615625

626+
_onFocus() {
627+
if (!this.disabled) {
628+
this.focused = true;
629+
this.stateChanges.next();
630+
}
631+
}
632+
616633
/**
617634
* Calls the touched callback only if the panel is closed. Otherwise, the trigger will
618635
* "blur" to the panel when it opens, causing a false positive.
619636
*/
620637
_onBlur() {
621638
if (!this.disabled && !this.panelOpen) {
639+
this.focused = false;
622640
this._onTouched();
623641
this._changeDetectorRef.markForCheck();
642+
this.stateChanges.next();
624643
}
625644
}
626645

@@ -1131,6 +1150,8 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
11311150
return 0;
11321151
}
11331152

1153+
/** Sets the list of element IDs that currently describe this select. */
1154+
setDescribedByIds(ids: string[]) { this._ariaDescribedby = ids.join(' '); }
11341155
}
11351156

11361157
/** Clamps a value n between min and max values. */

0 commit comments

Comments
 (0)