Skip to content

Commit 1a2a4e7

Browse files
committed
open select when form field is clicked
1 parent 2b7de29 commit 1a2a4e7

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ export abstract class MdFormFieldControl<T> {
4848
/** Sets the list of element IDs that currently describe this control. */
4949
abstract setDescribedByIds(ids: string[]): void;
5050

51-
/** Focuses this control. */
52-
abstract focus(): void;
51+
/** Handles a click on the control's container. */
52+
abstract onContainerClick(event: MouseEvent): void;
5353
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ let nextUniqueId = 0;
8282
'[class.ng-valid]': '_shouldForward("valid")',
8383
'[class.ng-invalid]': '_shouldForward("invalid")',
8484
'[class.ng-pending]': '_shouldForward("pending")',
85-
'(click)': '_control.focus()',
85+
'(click)': '_control.onContainerClick($event)',
8686
},
8787
encapsulation: ViewEncapsulation.None,
8888
changeDetection: ChangeDetectionStrategy.OnPush,

src/lib/input/input.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ export class MdInput implements MdFormFieldControl<any>, OnChanges, OnDestroy, D
197197
}
198198
}
199199

200+
focus() { this._elementRef.nativeElement.focus(); }
201+
200202
/** Callback for the cases where the focused state of the input changes. */
201203
_focusChanged(isFocused: boolean) {
202204
if (isFocused !== this.focused) {
@@ -282,5 +284,5 @@ export class MdInput implements MdFormFieldControl<any>, OnChanges, OnDestroy, D
282284
setDescribedByIds(ids: string[]) { this._ariaDescribedby = ids.join(' '); }
283285

284286
// Implemented as part of MdFormFieldControl.
285-
focus() { this._elementRef.nativeElement.focus(); }
287+
onContainerClick() { this.focus(); }
286288
}

src/lib/select/select.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,8 +1162,14 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
11621162
return 0;
11631163
}
11641164

1165-
/** Sets the list of element IDs that currently describe this select. */
1165+
// Implemented as part of MdFormFieldControl.
11661166
setDescribedByIds(ids: string[]) { this._ariaDescribedby = ids.join(' '); }
1167+
1168+
// Implemented as part of MdFormFieldControl.
1169+
onContainerClick() {
1170+
this.focus();
1171+
this.open();
1172+
}
11671173
}
11681174

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

0 commit comments

Comments
 (0)