Skip to content

Commit

Permalink
feat(input): add focus function on host element (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-merelis authored and jelbourn committed May 10, 2016
1 parent 523929c commit 0323844
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/input/input.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="md-input-wrapper" (click)="input.focus()">
<div class="md-input-wrapper">
<div class="md-input-table">
<div class="md-input-prefix"><ng-content select="[md-prefix]"></ng-content></div>

Expand Down
11 changes: 11 additions & 0 deletions src/components/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
ContentChild,
SimpleChange,
ContentChildren,
ViewChild,
ElementRef,
QueryList,
OnChanges,
} from '@angular/core';
Expand Down Expand Up @@ -94,6 +96,7 @@ export class MdHint {
templateUrl: 'components/input/input.html',
styleUrls: ['components/input/input.css'],
providers: [MD_INPUT_CONTROL_VALUE_ACCESSOR],
host: {'(click)' : 'focus()'}
})
export class MdInput implements ControlValueAccessor, AfterContentInit, OnChanges {
private _focused: boolean = false;
Expand Down Expand Up @@ -155,6 +158,14 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
// Input though, so we use HostBinding.
@HostBinding('attr.align') private get _align(): any { return null; }


@ViewChild('input') private _inputElement: ElementRef;

/** Set focus on input */
focus() {
this._inputElement.nativeElement.focus();

This comment has been minimized.

Copy link
@zoechi

zoechi Aug 21, 2016

Shouldn't this be something like

this.renderer.invokeElementMethod(this.elementRef.nativeElement, 'focus', []);

to not access members of nativeElement directly?

}

/** @internal */
onFocus() {
this._focused = true;
Expand Down

0 comments on commit 0323844

Please sign in to comment.