Skip to content

Commit 31c7e59

Browse files
committed
fix(searchbar): position elements when the value changes not after content checked
1 parent 9819aae commit 31c7e59

File tree

8 files changed

+68
-44
lines changed

8 files changed

+68
-44
lines changed

src/components/searchbar/searchbar.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,6 @@ export class Searchbar {
192192
this.positionElements();
193193
}
194194

195-
/**
196-
* @private
197-
* After Content is checked position the elements
198-
*/
199-
ngAfterContentChecked() {
200-
this.positionElements();
201-
}
202-
203195
/**
204196
* @private
205197
* Positions the input search icon, placeholder, and the cancel button
@@ -352,6 +344,7 @@ export class Searchbar {
352344
*/
353345
writeValue(val: any) {
354346
this._value = val;
347+
this.positionElements();
355348
}
356349

357350
/**
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<ion-navbar *navbar>
2+
<ion-title>Detail</ion-title>
3+
</ion-navbar>
4+
5+
<ion-content padding>
6+
<h1>City: {{city}}</h1>
7+
</ion-content>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
it('should navigate to searchbar', function() {
3-
element(by.css('.e2eSearchbarNav')).click();
2+
it('should navigate to details', function() {
3+
element(by.css('.e2eSearchbarNavItem')).click();
44
});

src/components/searchbar/test/nav/index.ts

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
import {Component} from '@angular/core';
2-
import {ionicBootstrap, NavController} from '../../../../../src';
1+
import { Component } from '@angular/core';
2+
import { ionicBootstrap, NavController, NavParams } from '../../../../../src';
33

44

55
@Component({
6-
templateUrl: 'first.html'
6+
templateUrl: 'main.html'
77
})
8-
class FirstPage {
9-
constructor(private _nav: NavController) {
10-
11-
}
8+
class MainPage {
9+
constructor(private _nav: NavController) { }
1210

1311
goToSecond() {
14-
this._nav.push(SecondPage);
12+
this._nav.push(SearchPage);
1513
}
1614
}
1715

1816
@Component({
19-
templateUrl: 'second.html'
17+
templateUrl: 'search.html'
2018
})
21-
class SecondPage {
22-
searchQuery = '';
19+
class SearchPage {
2320
items: string[];
2421

25-
constructor() {
22+
constructor(private _nav: NavController) {
2623
this.initializeItems();
2724
}
2825

26+
showDetail(item: any) {
27+
this._nav.push(DetailPage, {city: item});
28+
}
29+
2930
initializeItems() {
3031
this.items = [
3132
'Amsterdam',
@@ -68,15 +69,15 @@ class SecondPage {
6869
];
6970
}
7071

71-
getItems(searchbar) {
72+
getItems(ev: any) {
7273
// Reset items back to all of the items
7374
this.initializeItems();
7475

7576
// set q to the value of the searchbar
76-
var q = searchbar.value;
77+
var q = ev.target.value;
7778

7879
// if the value is an empty string don't filter the items
79-
if (q.trim() == '') {
80+
if (!q || q.trim() === '') {
8081
return;
8182
}
8283

@@ -89,11 +90,30 @@ class SecondPage {
8990
}
9091
}
9192

93+
@Component({
94+
templateUrl: 'detail.html'
95+
})
96+
class DetailPage {
97+
city: string;
98+
99+
constructor(private _navParams: NavParams) {
100+
this.city = _navParams.get('city');
101+
}
102+
}
103+
104+
@Component({
105+
templateUrl: 'tabs.html'
106+
})
107+
class TabsPage {
108+
mainPage = MainPage;
109+
searchPage = SearchPage;
110+
}
111+
92112
@Component({
93113
template: '<ion-nav [root]="root"></ion-nav>'
94114
})
95115
class E2EApp {
96-
root = FirstPage;
116+
root = TabsPage;
97117
}
98118

99119
ionicBootstrap(E2EApp);

src/components/searchbar/test/nav/first.html renamed to src/components/searchbar/test/nav/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
</ion-navbar>
44

55
<ion-content padding>
6-
<button block (click)="goToSecond()" class="e2eSearchbarNav">Go to Searchbar Page</button>
6+
<button block (click)="goToSecond()">Go to Searchbar Page</button>
77
</ion-content>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<ion-navbar *navbar>
2+
<ion-title>Searchbar</ion-title>
3+
</ion-navbar>
4+
5+
<ion-toolbar>
6+
<ion-searchbar primary (ionInput)="getItems($event)" placeholder="Filter Schedules">
7+
</ion-searchbar>
8+
</ion-toolbar>
9+
10+
<ion-content>
11+
<ion-searchbar (ionInput)="getItems($event)"></ion-searchbar>
12+
<ion-list>
13+
<button ion-item *ngFor="let item of items" (click)="showDetail(item)" class="e2eSearchbarNavItem">
14+
{{ item }}
15+
</button>
16+
</ion-list>
17+
</ion-content>

src/components/searchbar/test/nav/second.html

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<ion-tabs #content>
2+
<ion-tab tabTitle="Schedule" tabIcon="star" [root]="searchPage"></ion-tab>
3+
<ion-tab tabTitle="Navigate" tabIcon="globe" [root]="mainPage"></ion-tab>
4+
</ion-tabs>

0 commit comments

Comments
 (0)