Skip to content

Commit 3f5e888

Browse files
committed
Add highlight on selected item
1 parent 8935023 commit 3f5e888

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/app/app.component.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,41 @@ import { StatusBar, Splashscreen } from 'ionic-native';
1414

1515
import { HomePage } from '../pages/_home/home';
1616

17+
import { Subject } from 'rxjs';
18+
1719
@Component({
1820
templateUrl: 'app.html'
1921
})
2022
export class MyApp {
2123
@ViewChild(Nav) nav: Nav;
2224

2325
rootPage: any = HomePage;
26+
activePage = new Subject();
2427

25-
pages: Array<{ title: string, component: any }>;
28+
pages: Array<{ title: string, component: any, active: Boolean }>;
2629
state: any;
2730

2831
constructor(public platform: Platform, public global: AppState) {
2932
this.initializeApp();
3033

3134
this.pages = [
32-
{ title: 'Home', component: HomePage },
33-
{ title: 'Ionic Official Components', component: IonicOfficialComponentsPage },
34-
{ title: 'Login', component: LoginListPage },
35-
{ title: 'Lists', component: ListsPage },
36-
{ title: 'Popup Modal', component: PopupModalsPage },
37-
{ title: 'Miscellaneous', component: MiscellaneousListPage },
38-
{ title: 'Popup Menu', component: PopupMenuListPage },
39-
{ title: 'Profile', component: ProfileListPage },
35+
{ title: 'Home', component: HomePage, active: true },
36+
{ title: 'Ionic Official Components', component: IonicOfficialComponentsPage, active: false },
37+
{ title: 'Login', component: LoginListPage, active: false },
38+
{ title: 'Lists', component: ListsPage, active: false },
39+
{ title: 'Popup Modal', component: PopupModalsPage, active: false },
40+
{ title: 'Miscellaneous', component: MiscellaneousListPage, active: false },
41+
{ title: 'Popup Menu', component: PopupMenuListPage, active: false },
42+
{ title: 'Profile', component: ProfileListPage, active: false },
4043
// Removed for now as there were breaking changes in slides
4144
// { title: 'Slides', component: SlidesPage },
42-
{ title: 'Theming', component: ThemingPage },
45+
{ title: 'Theming', component: ThemingPage, active: false },
4346
];
4447

48+
this.activePage.subscribe((value: any) => {
49+
this.pages.map(x => x.active = false);
50+
this.pages[this.pages.findIndex(x => x.title === value.title)].active = true;
51+
});
4552
}
4653

4754
initializeApp() {
@@ -58,5 +65,6 @@ export class MyApp {
5865
// Reset the content nav to have just this page
5966
// we wouldn't want the back button to show in this scenario
6067
this.nav.setRoot(page.component);
68+
this.activePage.next(page);
6169
}
6270
}

src/app/app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</ion-header>
88
<ion-content>
99
<ion-list>
10-
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
10+
<button menuClose ion-item *ngFor="let p of pages" [class.highlight]="p.active" (click)="openPage(p)">
1111
{{p.title}}
1212
</button>
1313
</ion-list>

src/app/app.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
text-align: center;
2020
}
2121

22+
.highlight {
23+
background-color: #f4f4f4;
24+
}
25+
2226
.center {
2327
display: block;
2428
margin: 0 auto;

0 commit comments

Comments
 (0)