Skip to content

Commit 5c15857

Browse files
committed
feat(combo): made filtering pipe pure #7282
1 parent f8cdc44 commit 5c15857

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

projects/igniteui-angular/src/lib/combo/combo.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
aria-autocomplete="both" [attr.aria-owns]="dropdown.id" [attr.aria-labelledby]="ariaLabelledBy" />
4242
<igx-suffix *ngIf="showSearchCaseIcon">
4343
<igx-icon fontSet="case-sensitive" name="case-sensitive" [isActive]="filteringOptions.caseSensitive"
44-
(click)="filteringOptions.caseSensitive=!filteringOptions.caseSensitive">
44+
(click)="toggleCaseSensitive()">
4545
</igx-icon>
4646
</igx-suffix>
4747
</igx-input-group>
@@ -51,7 +51,7 @@
5151
[style.maxHeight.px]="itemsMaxHeight" [igxDropDownItemNavigation]="dropdown" (focus)="dropdown.onFocus()"
5252
[tabindex]="dropdown.collapsed ? -1 : 0" role="listbox" [attr.id]="dropdown.id">
5353
<igx-combo-item role="option" [itemHeight]='itemHeight' *igxFor="let item of data
54-
| comboFiltering:searchValue:displayKey:filterable:filteringOptions
54+
| comboFiltering:searchValue:displayKey:filterable:filteringOptions:filteringPipeTrigger
5555
| comboGrouping:groupKey:valueKey;
5656
index as rowIndex; containerSize: itemsMaxHeight; scrollOrientation: 'vertical'; itemSize: itemHeight"
5757
[value]="item" [isHeader]="item.isHeader" [index]="rowIndex">

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,22 +2005,22 @@ describe('igxCombo', () => {
20052005
combo.searchValue = 'New ';
20062006
combo.handleInputChange();
20072007
fixture.detectChanges();
2008-
expect(filterSpy).toHaveBeenCalledTimes(2);
2008+
expect(filterSpy).toHaveBeenCalledTimes(1);
20092009
expect(combo.filteredData.length).toBeLessThan(initialData.length);
20102010

20112011
firstFilter = [...combo.filteredData];
20122012
combo.searchValue += ' ';
20132013
combo.handleInputChange();
20142014
fixture.detectChanges();
20152015
expect(combo.filteredData.length).toBeLessThan(initialData.length);
2016-
expect(filterSpy).toHaveBeenCalledTimes(4);
2016+
expect(filterSpy).toHaveBeenCalledTimes(2);
20172017

20182018
combo.searchValue = '';
20192019
combo.handleInputChange();
20202020
fixture.detectChanges();
20212021
expect(combo.filteredData.length).toEqual(initialData.length);
20222022
expect(combo.filteredData.length).toBeGreaterThan(firstFilter.length);
2023-
expect(filterSpy).toHaveBeenCalledTimes(6);
2023+
expect(filterSpy).toHaveBeenCalledTimes(3);
20242024
expect(combo.filteredData.length).toEqual(initialData.length);
20252025
});
20262026
it('should properly select/deselect filteredData', () => {
@@ -2033,7 +2033,7 @@ describe('igxCombo', () => {
20332033
combo.searchValue = 'New ';
20342034
combo.handleInputChange();
20352035
fixture.detectChanges();
2036-
expect(filterSpy).toHaveBeenCalledTimes(2);
2036+
expect(filterSpy).toHaveBeenCalledTimes(1);
20372037
expect(combo.filteredData.length).toBeLessThan(initialData.length);
20382038
expect(combo.filteredData.length).toEqual(4);
20392039

projects/igniteui-angular/src/lib/combo/combo.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
165165
public filteringOptions: IComboFilteringOptions = {
166166
caseSensitive: false
167167
};
168+
/**
169+
* @hidden @internal
170+
*/
171+
public filteringPipeTrigger = 0;
168172
protected stringFilters = IgxStringFilteringOperand;
169173
protected booleanFilters = IgxBooleanFilteringOperand;
170174
protected _groupKey = '';
@@ -1578,6 +1582,14 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
15781582
public handleClosed() {
15791583
this.onClosed.emit();
15801584
}
1585+
1586+
/**
1587+
* @hidden @internal
1588+
*/
1589+
public toggleCaseSensitive() {
1590+
this.filteringOptions.caseSensitive = !this.filteringOptions.caseSensitive;
1591+
this.filteringPipeTrigger++;
1592+
}
15811593
}
15821594

15831595
/**

projects/igniteui-angular/src/lib/combo/combo.pipes.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import { IComboFilteringOptions } from './combo.component';
1111
* @hidden
1212
*/
1313
@Pipe({
14-
name: 'comboFiltering',
15-
pure: false
14+
name: 'comboFiltering'
1615
})
1716
export class IgxComboFilteringPipe implements PipeTransform {
1817
public transform(collection: any[], searchValue: any, displayKey: any,
19-
shouldFilter: boolean, filteringOptions: IComboFilteringOptions) {
18+
shouldFilter: boolean, filteringOptions: IComboFilteringOptions, pipeTrigger: number) {
2019
if (!collection) {
2120
return [];
2221
}

0 commit comments

Comments
 (0)