From 3e88fe9f313fa55e11e49deabf7cc9fb5f30dd2b Mon Sep 17 00:00:00 2001 From: Brandy Carney Date: Wed, 16 Mar 2016 12:46:27 -0400 Subject: [PATCH] fix(input): add event emitters for blur and focus to the ion-input component fixes #5487 --- ionic/components/input/input-base.ts | 2 ++ ionic/components/input/input.ts | 34 +++++++++++++++++-- .../input/test/fixed-inline-labels/index.ts | 18 +++++++--- .../input/test/fixed-inline-labels/main.html | 12 +++++-- 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/ionic/components/input/input-base.ts b/ionic/components/input/input-base.ts index 4f125167212..d6e8ceaf59d 100644 --- a/ionic/components/input/input-base.ts +++ b/ionic/components/input/input-base.ts @@ -33,6 +33,8 @@ export class InputBase { @Input() clearInput; @Input() placeholder: string = ''; @ViewChild(NativeInput) protected _native: NativeInput; + @Output() blur: EventEmitter = new EventEmitter; + @Output() focus: EventEmitter = new EventEmitter; constructor( config: Config, diff --git a/ionic/components/input/input.ts b/ionic/components/input/input.ts index e5ec1e5aa9d..15f62b1662f 100644 --- a/ionic/components/input/input.ts +++ b/ionic/components/input/input.ts @@ -1,4 +1,4 @@ -import {Component, Optional, ElementRef} from 'angular2/core'; +import {Component, Optional, ElementRef, ViewChild} from 'angular2/core'; import {NgIf, NgControl} from 'angular2/common'; import {Button} from '../button/button'; @@ -65,7 +65,7 @@ import {Platform} from '../../platform/platform'; @Component({ selector: 'ion-input', template: - '' + + '' + '' + '' + '
', @@ -90,6 +90,20 @@ export class TextInput extends InputBase { ) { super(config, form, item, app, platform, elementRef, scrollView, nav, ngControl); } + + /** + * @private + */ + inputBlurred(event) { + this.blur.emit(event); + } + + /** + * @private + */ + inputFocused(event) { + this.focus.emit(event); + } } @@ -134,7 +148,7 @@ export class TextInput extends InputBase { @Component({ selector: 'ion-textarea', template: - '' + + '' + '' + '
', directives: [ @@ -167,4 +181,18 @@ export class TextArea extends InputBase { this._item.setCssClass('item-textarea', true); } } + + /** + * @private + */ + inputBlurred(event) { + this.blur.emit(event); + } + + /** + * @private + */ + inputFocused(event) { + this.focus.emit(event); + } } diff --git a/ionic/components/input/test/fixed-inline-labels/index.ts b/ionic/components/input/test/fixed-inline-labels/index.ts index 4ed6115669c..c14f6553c23 100644 --- a/ionic/components/input/test/fixed-inline-labels/index.ts +++ b/ionic/components/input/test/fixed-inline-labels/index.ts @@ -1,13 +1,21 @@ -import {App} from 'ionic-angular'; +import {App, Page} from 'ionic-angular'; -@App({ +@Page({ templateUrl: 'main.html' }) -class E2EApp { +class PageOne { url; + input1: string = 'Text 1'; - constructor() { - this.input1 = 'Text 1'; + onEvent(event) { + console.log("Did Event:", event.type); } } + +@App({ + template: '' +}) +class E2EApp { + root = PageOne; +} diff --git a/ionic/components/input/test/fixed-inline-labels/main.html b/ionic/components/input/test/fixed-inline-labels/main.html index 84efa016fa3..42f0b059763 100644 --- a/ionic/components/input/test/fixed-inline-labels/main.html +++ b/ionic/components/input/test/fixed-inline-labels/main.html @@ -9,7 +9,11 @@ To - + + @@ -29,7 +33,11 @@ Comments - + +