Skip to content

Commit b817391

Browse files
authored
Merge pull request #16966 from IgniteUI/dpetev/dev-demos-nav-filter
chore(demos): add basic side nav filter
2 parents fea6f19 + 9e87537 commit b817391

2 files changed

Lines changed: 63 additions & 14 deletions

File tree

src/app/app.component.html

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,28 @@
77
<ng-template igxDrawer>
88
<div class="nav-header"></div>
99

10+
<!-- Filter Input -->
11+
<igx-input-group type="search" style="margin: 8px;">
12+
<igx-prefix>
13+
<igx-icon>filter_alt</igx-icon>
14+
</igx-prefix>
15+
<input igxInput placeholder="Filter..." [(ngModel)]="filterText" />
16+
@if (filterText()) {
17+
<igx-suffix>
18+
<igx-icon (click)="filterText.set('')">clear</igx-icon>
19+
</igx-suffix>
20+
}
21+
</igx-input-group>
22+
1023
<!-- Components -->
1124
<span igxDrawerItem [isHeader]="true">Components</span>
1225

13-
@for (item of componentLinks; track item) {
14-
<span igxDrawerItem igxRipple routerLinkActive="igx-nav-drawer__item--active" routerLink="{{item.link}}">
15-
<igx-icon>{{item.icon}}</igx-icon>
16-
<span class="navdrawer-ellipsis">{{item.name}}</span>
17-
</span>
18-
}
26+
@for (item of filteredComponentLinks(); track item) {
27+
<span igxDrawerItem igxRipple routerLinkActive="igx-nav-drawer__item--active" routerLink="{{item.link}}">
28+
<igx-icon>{{item.icon}}</igx-icon>
29+
<span class="navdrawer-ellipsis">{{item.name}}</span>
30+
</span>
31+
}
1932

2033
<span igxDrawerItem [disabled]="true">
2134
<igx-icon>web</igx-icon>
@@ -25,17 +38,17 @@
2538
<!--Directives-->
2639
<span igxDrawerItem [isHeader]="true">Directives</span>
2740

28-
@for (item of directiveLinks; track item) {
29-
<span igxDrawerItem igxRipple routerLinkActive="igx-nav-drawer__item--active" routerLink="{{item.link}}">
30-
<igx-icon>{{item.icon}}</igx-icon>
31-
<span class="navdrawer-ellipsis">{{item.name}}</span>
32-
</span>
33-
}
41+
@for (item of filteredDirectiveLinks(); track item) {
42+
<span igxDrawerItem igxRipple routerLinkActive="igx-nav-drawer__item--active" routerLink="{{item.link}}">
43+
<igx-icon>{{item.icon}}</igx-icon>
44+
<span class="navdrawer-ellipsis">{{item.name}}</span>
45+
</span>
46+
}
3447

3548
<!--Style guide-->
3649
<span igxDrawerItem [isHeader]="true">Style</span>
3750

38-
@for (item of styleLinks; track item) {
51+
@for (item of filteredStyleLinks(); track item) {
3952
<span igxDrawerItem igxRipple routerLinkActive="igx-nav-drawer__item--active" routerLink="{{item.link}}">
4053
<igx-icon>{{item.icon}}</igx-icon>
4154
<span class="navdrawer-ellipsis">{{item.name}}</span>

src/app/app.component.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ import {
44
ViewChild,
55
HostBinding,
66
inject,
7-
signal
7+
signal,
8+
computed,
89
} from '@angular/core';
910
import { Router, NavigationStart, NavigationEnd, RouterLinkActive, RouterLink, RouterOutlet } from '@angular/router';
1011
import { filter } from 'rxjs/operators';
1112
import { DocumentDirection, PageHeaderComponent } from './pageHeading/pageHeading.component';
1213
import { CommonModule, registerLocaleData } from '@angular/common';
14+
import { FormsModule } from '@angular/forms';
1315
import { PropertiesPanelComponent } from './properties-panel/properties-panel.component';
1416
import { PropertyChangeService } from './properties-panel/property-change.service';
1517
import { IGX_NAVIGATION_DRAWER_DIRECTIVES, IgxNavigationDrawerComponent } from 'igniteui-angular/navigation-drawer';
1618
import { IgxIconComponent, IgxIconService } from 'igniteui-angular/icon';
1719
import { IgxRippleDirective } from 'igniteui-angular/directives';
20+
import { IgxInputGroupComponent, IgxInputDirective, IgxPrefixDirective, IgxSuffixDirective } from 'igniteui-angular/input-group';
1821

1922
// I18n
2023
import { registerI18n } from 'igniteui-angular';
@@ -38,12 +41,17 @@ import localeHant from '@angular/common/locales/zh-Hant';
3841
IgxNavigationDrawerComponent,
3942
IGX_NAVIGATION_DRAWER_DIRECTIVES,
4043
CommonModule,
44+
FormsModule,
4145
RouterLinkActive,
4246
RouterLink,
4347
IgxIconComponent,
4448
PageHeaderComponent,
4549
RouterOutlet,
4650
IgxRippleDirective,
51+
IgxInputGroupComponent,
52+
IgxInputDirective,
53+
IgxPrefixDirective,
54+
IgxSuffixDirective,
4755
PropertiesPanelComponent,
4856
]
4957
})
@@ -56,6 +64,9 @@ export class AppComponent implements OnInit {
5664

5765
public dirMode = signal<'ltr' | 'rtl'>('ltr');
5866

67+
// Filter for navigation items
68+
public filterText = signal('');
69+
5970
// This method will be triggered by PageHeaderComponent's toggleDirection event
6071
public onDirectionToggle(dir: DocumentDirection): void {
6172
this.dirMode.set(dir);
@@ -777,6 +788,31 @@ export class AppComponent implements OnInit {
777788
}
778789
].sort((componentLink1, componentLink2) => componentLink1.name > componentLink2.name ? 1 : -1);
779790

791+
// Computed filtered arrays
792+
public filteredComponentLinks = computed(() => {
793+
const filterValue = this.filterText().toLowerCase();
794+
if (!filterValue) {
795+
return this.componentLinks;
796+
}
797+
return this.componentLinks.filter(item => item.name.toLowerCase().includes(filterValue));
798+
});
799+
800+
public filteredDirectiveLinks = computed(() => {
801+
const filterValue = this.filterText().toLowerCase();
802+
if (!filterValue) {
803+
return this.directiveLinks;
804+
}
805+
return this.directiveLinks.filter(item => item.name.toLowerCase().includes(filterValue));
806+
});
807+
808+
public filteredStyleLinks = computed(() => {
809+
const filterValue = this.filterText().toLowerCase();
810+
if (!filterValue) {
811+
return this.styleLinks;
812+
}
813+
return this.styleLinks.filter(item => item.name.toLowerCase().includes(filterValue));
814+
});
815+
780816
constructor(private router: Router, private iconService: IgxIconService) {
781817
iconService.setFamily('fa-solid', { className: 'fa', type: 'font', prefix: 'fa-'});
782818
iconService.setFamily('fa-brands', { className: 'fab', type: 'font' });

0 commit comments

Comments
 (0)