Skip to content

Commit 0323844

Browse files
jean-merelisjelbourn
authored andcommitted
feat(input): add focus function on host element (#407)
1 parent 523929c commit 0323844

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/components/input/input.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="md-input-wrapper" (click)="input.focus()">
1+
<div class="md-input-wrapper">
22
<div class="md-input-table">
33
<div class="md-input-prefix"><ng-content select="[md-prefix]"></ng-content></div>
44

src/components/input/input.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
ContentChild,
1010
SimpleChange,
1111
ContentChildren,
12+
ViewChild,
13+
ElementRef,
1214
QueryList,
1315
OnChanges,
1416
} from '@angular/core';
@@ -94,6 +96,7 @@ export class MdHint {
9496
templateUrl: 'components/input/input.html',
9597
styleUrls: ['components/input/input.css'],
9698
providers: [MD_INPUT_CONTROL_VALUE_ACCESSOR],
99+
host: {'(click)' : 'focus()'}
97100
})
98101
export class MdInput implements ControlValueAccessor, AfterContentInit, OnChanges {
99102
private _focused: boolean = false;
@@ -155,6 +158,14 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
155158
// Input though, so we use HostBinding.
156159
@HostBinding('attr.align') private get _align(): any { return null; }
157160

161+
162+
@ViewChild('input') private _inputElement: ElementRef;
163+
164+
/** Set focus on input */
165+
focus() {
166+
this._inputElement.nativeElement.focus();
167+
}
168+
158169
/** @internal */
159170
onFocus() {
160171
this._focused = true;

0 commit comments

Comments
 (0)