Skip to content

Commit

Permalink
fix(input): prevent exception when input components outside Content
Browse files Browse the repository at this point in the history
  • Loading branch information
jsayol authored and adamdbradley committed Dec 14, 2016
1 parent 4f61ea5 commit e80f4cf
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
19 changes: 11 additions & 8 deletions src/components/input/input-base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementRef, Renderer } from '@angular/core';
import { ElementRef, Renderer, Optional } from '@angular/core';
import { NgControl } from '@angular/forms';

import { App } from '../app/app';
Expand Down Expand Up @@ -52,7 +52,7 @@ export class InputBase extends Ion implements IonicFormInput {
protected _platform: Platform,
elementRef: ElementRef,
renderer: Renderer,
protected _content: Content,
@Optional() protected _content: Content,
nav: NavController,
ngControl: NgControl,
protected _dom: DomController
Expand All @@ -75,12 +75,15 @@ export class InputBase extends Ion implements IonicFormInput {

_form.register(this);

this._scrollStart = _content.ionScrollStart.subscribe((ev: ScrollEvent) => {
this.scrollHideFocus(ev, true);
});
this._scrollEnd = _content.ionScrollEnd.subscribe((ev: ScrollEvent) => {
this.scrollHideFocus(ev, false);
});
// only listen to content scroll events if there is content
if (_content) {
this._scrollStart = _content.ionScrollStart.subscribe((ev: ScrollEvent) => {
this.scrollHideFocus(ev, true);
});
this._scrollEnd = _content.ionScrollEnd.subscribe((ev: ScrollEvent) => {
this.scrollHideFocus(ev, false);
});
}
}

scrollHideFocus(ev: ScrollEvent, shouldHideFocus: boolean) {
Expand Down
16 changes: 12 additions & 4 deletions src/components/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ export class TextInput extends InputBase {
*/
ngOnDestroy() {
this._form.deregister(this);
this._scrollStart.unsubscribe();
this._scrollEnd.unsubscribe();

// only stop listening to content scroll events if there is content
if (this._content) {
this._scrollStart.unsubscribe();
this._scrollEnd.unsubscribe();
}
}

/**
Expand Down Expand Up @@ -410,8 +414,12 @@ export class TextArea extends InputBase {
*/
ngOnDestroy() {
this._form.deregister(this);
this._scrollStart.unsubscribe();
this._scrollEnd.unsubscribe();

// only stop listening to content scroll events if there is content
if (this._content) {
this._scrollStart.unsubscribe();
this._scrollEnd.unsubscribe();
}
}

/**
Expand Down
31 changes: 31 additions & 0 deletions src/components/input/test/footer-inputs/app-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Component, NgModule } from '@angular/core';
import { IonicApp, IonicModule } from '../../../..';


@Component({
templateUrl: 'main.html'
})
export class E2EPage {
}

@Component({
template: '<ion-nav [root]="rootPage"></ion-nav>'
})
export class E2EApp {
rootPage = E2EPage;
}

@NgModule({
declarations: [
E2EApp,
E2EPage
],
imports: [
IonicModule.forRoot(E2EApp)
],
bootstrap: [IonicApp],
entryComponents: [
E2EPage
]
})
export class AppModule {}
1 change: 1 addition & 0 deletions src/components/input/test/footer-inputs/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

17 changes: 17 additions & 0 deletions src/components/input/test/footer-inputs/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<ion-header>
<ion-navbar>
<ion-title>Inputs in footer</ion-title>
</ion-navbar>
</ion-header>

<ion-content padding>
<p>TextInput and TextArea components should work outside of a Content component.</p>
</ion-content>

<ion-footer>

<ion-input></ion-input>

<ion-textarea></ion-textarea>

</ion-footer>

0 comments on commit e80f4cf

Please sign in to comment.