Skip to content

Commit

Permalink
feat(combo): Add caseSensitive option and make onSearchInput cancelable
Browse files Browse the repository at this point in the history
  • Loading branch information
PlamenaMiteva committed Jul 8, 2020
1 parent 7535a21 commit 34c9d0d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
7 changes: 6 additions & 1 deletion projects/igniteui-angular/src/lib/combo/combo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
[(ngModel)]="searchValue" (ngModelChange)="handleInputChange($event)" (keyup)="handleKeyUp($event)"
(keydown)="handleKeyDown($event)" (focus)="dropdown.onBlur($event)" [attr.placeholder]="searchPlaceholder"
aria-autocomplete="both" [attr.aria-owns]="dropdown.id" [attr.aria-labelledby]="ariaLabelledBy" />
<igx-suffix igxButton="icon" (click)="caseSensitive=!caseSensitive">
<igx-icon fontSet="material">
{{ caseSensitive ? 'format_size' : 'format_clear'}}
</igx-icon>
</igx-suffix>
</igx-input-group>
<ng-container *ngTemplateOutlet="headerTemplate">
</ng-container>
Expand All @@ -47,7 +52,7 @@
[tabindex]="dropdown.collapsed ? -1 : 0" role="listbox" [attr.id]="dropdown.id">
<igx-combo-item role="option" [itemHeight]='itemHeight'
*igxFor="let item of data
| comboFiltering:searchValue:displayKey:filterable
| comboFiltering:searchValue:displayKey:filterable:caseSensitive
| comboGrouping:groupKey:valueKey;
index as rowIndex; containerSize: itemsMaxHeight; scrollOrientation: 'vertical'; itemSize: itemHeight"
[value]="item" [isHeader]="item.isHeader" [index]="rowIndex">
Expand Down
38 changes: 34 additions & 4 deletions projects/igniteui-angular/src/lib/combo/combo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export interface IComboItemAdditionEvent extends IBaseEventArgs {
newCollection: any[];
}

/** Event emitted when the igx-combo's search input changes */
export interface IComboSearchInputEventArgs extends CancelableEventArgs {
/** The change that has been made to the search input */
change: string;
}

/**
* When called with sets A & B, returns A - B (as array);
* @hidden
Expand Down Expand Up @@ -484,7 +490,7 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
* ```
*/
@Output()
public onSearchInput = new EventEmitter();
public onSearchInput = new EventEmitter<IComboSearchInputEventArgs>();

/**
* Emitted when new chunk of data is loaded from the virtualization
Expand Down Expand Up @@ -692,6 +698,22 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
@Input()
public searchPlaceholder = 'Enter a Search Term';

/**
* Sets the caseSensitive option of the combo filtering
*
* ```typescript
* // get
* let myComboCaseSensitiveFilter = this.combo.caseSensitive;
* ```
*
* ```html
* <!--set-->
* <igx-combo [caseSensitive]='true'></igx-combo>
* ```
*/
@Input()
public caseSensitive = false;

/**
* Combo data source.
*
Expand Down Expand Up @@ -982,8 +1004,16 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
*/
public handleInputChange(event?: string) {
if (event !== undefined) {
this.onSearchInput.emit(event);
const args: IComboSearchInputEventArgs = {
change: event,
cancel: false
};
this.onSearchInput.emit(args);
if (args.cancel) {
this.searchValue = null;
return;
}
}
this.checkMatch();
}

Expand Down Expand Up @@ -1437,8 +1467,8 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
/** Returns a string that should be populated in the combo's text box */
private concatDisplayText(selection: any[]): string {
const value = this.displayKey !== null && this.displayKey !== undefined ?
this.convertKeysToItems(selection).map(entry => entry[this.displayKey]).join(', ') :
selection.join(', ');
this.convertKeysToItems(selection).map(entry => entry[this.displayKey]).join(', ') :
selection.join(', ');
return value;
}

Expand Down
9 changes: 5 additions & 4 deletions projects/igniteui-angular/src/lib/combo/combo.pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ import { DefaultSortingStrategy } from '../data-operations/sorting-strategy';
name: 'comboFiltering'
})
export class IgxComboFilteringPipe implements PipeTransform {
public transform(collection: any[], searchValue: any, displayKey: any, shouldFilter: boolean) {
public transform(collection: any[], searchValue: any, displayKey: any, shouldFilter: boolean, caseSensitive: boolean) {
if (!collection) {
return [];
}
if (!searchValue || !shouldFilter) {
return collection;
} else {
const searchTerm = searchValue.toLowerCase().trim();
const searchTerm = caseSensitive ? searchValue.trim() : searchValue.toLowerCase().trim();
if (displayKey != null) {
return collection.filter(e => e[displayKey].toLowerCase().includes(searchTerm));
return collection.filter(e => caseSensitive ? e[displayKey].includes(searchTerm) :
e[displayKey].toLowerCase().includes(searchTerm));
} else {
return collection.filter(e => e.toLowerCase().includes(searchTerm));
return collection.filter(e => caseSensitive ? e.includes(searchTerm) : e.toLowerCase().includes(searchTerm));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/app/combo/combo.sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
[allowCustomValues]="customValuesFlag"
[displayDensity]="'comfortable'"
[autoFocusSearch]="autoFocusSearch"
(onSearchInput)="handleSearchInputEvent($event)"
[filterable]="filterableFlag" [displayKey]="valueKeyVar" [valueKey]="valueKeyVar"
[groupKey]="valueKeyVar ? 'region' : ''" [width]="'100%'">
<ng-template *ngIf="currentDataType !== 'primitive'" #itemTemplate let-display let-key="valueKey">
Expand Down
13 changes: 9 additions & 4 deletions src/app/combo/combo.sample.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, ViewChild, OnInit, TemplateRef, AfterViewInit, ElementRef } from '@angular/core';
import { IgxComboComponent, IComboSelectionChangeEventArgs,
DisplayDensity, OverlaySettings, AutoPositionStrategy, VerticalAlignment, HorizontalAlignment, GlobalPositionStrategy,
scaleInCenter, scaleOutCenter, ElasticPositionStrategy
scaleInCenter, scaleOutCenter, ElasticPositionStrategy, CancelableEventArgs
} from 'igniteui-angular';
import { take } from 'rxjs/operators';
import { cloneDeep } from 'lodash';
Expand Down Expand Up @@ -156,9 +156,10 @@ export class ComboSampleComponent implements OnInit, AfterViewInit {
console.log('Closed log!');
});

this.igxCombo.onSearchInput.subscribe((e) => {
console.log(e);
});
// this.igxCombo.onSearchInput.subscribe((e) => {
// e.cancel = true;
// console.log(e);
// });
}

ngAfterViewInit() {
Expand Down Expand Up @@ -194,4 +195,8 @@ export class ComboSampleComponent implements OnInit, AfterViewInit {
handleSelectionChange(event: IComboSelectionChangeEventArgs) {
console.log(event);
}

handleSearchInputEvent(event: CancelableEventArgs) {
// event.cancel = true;
}
}

0 comments on commit 34c9d0d

Please sign in to comment.