Skip to content

Commit e80f4cf

Browse files
jsayoladamdbradley
authored andcommitted
fix(input): prevent exception when input components outside Content
1 parent 4f61ea5 commit e80f4cf

File tree

5 files changed

+72
-12
lines changed

5 files changed

+72
-12
lines changed

src/components/input/input-base.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ElementRef, Renderer } from '@angular/core';
1+
import { ElementRef, Renderer, Optional } from '@angular/core';
22
import { NgControl } from '@angular/forms';
33

44
import { App } from '../app/app';
@@ -52,7 +52,7 @@ export class InputBase extends Ion implements IonicFormInput {
5252
protected _platform: Platform,
5353
elementRef: ElementRef,
5454
renderer: Renderer,
55-
protected _content: Content,
55+
@Optional() protected _content: Content,
5656
nav: NavController,
5757
ngControl: NgControl,
5858
protected _dom: DomController
@@ -75,12 +75,15 @@ export class InputBase extends Ion implements IonicFormInput {
7575

7676
_form.register(this);
7777

78-
this._scrollStart = _content.ionScrollStart.subscribe((ev: ScrollEvent) => {
79-
this.scrollHideFocus(ev, true);
80-
});
81-
this._scrollEnd = _content.ionScrollEnd.subscribe((ev: ScrollEvent) => {
82-
this.scrollHideFocus(ev, false);
83-
});
78+
// only listen to content scroll events if there is content
79+
if (_content) {
80+
this._scrollStart = _content.ionScrollStart.subscribe((ev: ScrollEvent) => {
81+
this.scrollHideFocus(ev, true);
82+
});
83+
this._scrollEnd = _content.ionScrollEnd.subscribe((ev: ScrollEvent) => {
84+
this.scrollHideFocus(ev, false);
85+
});
86+
}
8487
}
8588

8689
scrollHideFocus(ev: ScrollEvent, shouldHideFocus: boolean) {

src/components/input/input.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,12 @@ export class TextInput extends InputBase {
240240
*/
241241
ngOnDestroy() {
242242
this._form.deregister(this);
243-
this._scrollStart.unsubscribe();
244-
this._scrollEnd.unsubscribe();
243+
244+
// only stop listening to content scroll events if there is content
245+
if (this._content) {
246+
this._scrollStart.unsubscribe();
247+
this._scrollEnd.unsubscribe();
248+
}
245249
}
246250

247251
/**
@@ -410,8 +414,12 @@ export class TextArea extends InputBase {
410414
*/
411415
ngOnDestroy() {
412416
this._form.deregister(this);
413-
this._scrollStart.unsubscribe();
414-
this._scrollEnd.unsubscribe();
417+
418+
// only stop listening to content scroll events if there is content
419+
if (this._content) {
420+
this._scrollStart.unsubscribe();
421+
this._scrollEnd.unsubscribe();
422+
}
415423
}
416424

417425
/**
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Component, NgModule } from '@angular/core';
2+
import { IonicApp, IonicModule } from '../../../..';
3+
4+
5+
@Component({
6+
templateUrl: 'main.html'
7+
})
8+
export class E2EPage {
9+
}
10+
11+
@Component({
12+
template: '<ion-nav [root]="rootPage"></ion-nav>'
13+
})
14+
export class E2EApp {
15+
rootPage = E2EPage;
16+
}
17+
18+
@NgModule({
19+
declarations: [
20+
E2EApp,
21+
E2EPage
22+
],
23+
imports: [
24+
IonicModule.forRoot(E2EApp)
25+
],
26+
bootstrap: [IonicApp],
27+
entryComponents: [
28+
E2EPage
29+
]
30+
})
31+
export class AppModule {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<ion-header>
2+
<ion-navbar>
3+
<ion-title>Inputs in footer</ion-title>
4+
</ion-navbar>
5+
</ion-header>
6+
7+
<ion-content padding>
8+
<p>TextInput and TextArea components should work outside of a Content component.</p>
9+
</ion-content>
10+
11+
<ion-footer>
12+
13+
<ion-input></ion-input>
14+
15+
<ion-textarea></ion-textarea>
16+
17+
</ion-footer>

0 commit comments

Comments
 (0)