Skip to content

Commit 2612024

Browse files
authored
Merge pull request yannbf#16 from Fdom92/feature/fdom/highlight-item
Adds highlight on selected menu item
2 parents 81ef354 + 0e652e2 commit 2612024

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/app/app.component.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,42 @@ 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((selectedPage: any) => {
49+
this.pages.map(page => {
50+
page.active = page.title === selectedPage.title;
51+
});
52+
});
4553
}
4654

4755
initializeApp() {
@@ -58,5 +66,6 @@ export class MyApp {
5866
// Reset the content nav to have just this page
5967
// we wouldn't want the back button to show in this scenario
6068
this.nav.setRoot(page.component);
69+
this.activePage.next(page);
6170
}
6271
}

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)