Skip to content

Commit 0c00dae

Browse files
authored
Merge pull request #8034 from IgniteUI/vslavov/combo-searchinput-fix-10.1.x
fix(combo): fix error in searchvalue handling - 10.1.x
2 parents c4d05a0 + 251b2ea commit 0c00dae

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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:filterValue:displayKey:filterable:filteringOptions
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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { async, TestBed, tick, fakeAsync } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55
import { FormGroup, FormControl, Validators, FormBuilder, ReactiveFormsModule, FormsModule, NgControl } from '@angular/forms';
6-
import { IgxComboComponent, IgxComboModule, IComboSelectionChangeEventArgs, IgxComboState } from './combo.component';
6+
import { IgxComboComponent, IgxComboModule, IComboSelectionChangeEventArgs, IgxComboState, IComboSearchInputEventArgs } from './combo.component';
77
import { IgxComboItemComponent } from './combo-item.component';
88
import { IgxComboDropDownComponent } from './combo-dropdown.component';
99
import { IgxComboAddItemComponent } from './combo-add-item.component';
@@ -586,7 +586,7 @@ describe('igxCombo', () => {
586586

587587
combo.handleInputChange('Item1');
588588
expect(combo.onSearchInput.emit).toHaveBeenCalledTimes(1);
589-
expect(matchSpy).toHaveBeenCalledTimes(0);
589+
expect(matchSpy).toHaveBeenCalledTimes(1);
590590
});
591591
});
592592
describe('Initialization and rendering tests: ', () => {
@@ -2432,6 +2432,17 @@ describe('igxCombo', () => {
24322432
fixture.detectChanges();
24332433
expect([...combo.filteredData]).toEqual(combo.data.filter(e => e['field'].includes('M')));
24342434
});
2435+
it('Should NOT filter the data when onSearchInput is canceled', () => {
2436+
const cancelSub = combo.onSearchInput.subscribe((event: IComboSearchInputEventArgs) => event.cancel = true);
2437+
combo.toggle();
2438+
fixture.detectChanges();
2439+
const searchInput = fixture.debugElement.query(By.css('input[name=\'searchInput\']'));
2440+
UIInteractions.triggerInputEvent(searchInput, 'Test');
2441+
fixture.detectChanges();
2442+
expect(combo.filteredData.length).toEqual(combo.data.length);
2443+
expect(combo.searchValue).toEqual('Test');
2444+
cancelSub.unsubscribe();
2445+
});
24352446
});
24362447
describe('Form control tests: ', () => {
24372448
describe('Reactive form tests: ', () => {

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,15 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
165165
public filteringOptions: IComboFilteringOptions = {
166166
caseSensitive: false
167167
};
168+
/** @hidden @internal */
169+
public filterValue = '';
168170
protected stringFilters = IgxStringFilteringOperand;
169171
protected booleanFilters = IgxBooleanFilteringOperand;
170172
protected _groupKey = '';
171173
protected _displayKey: string;
172174
protected _prevInputValue = '';
173175
private _dataType = '';
176+
private _searchValue = '';
174177
private ngControl: NgControl = null;
175178
private destroy$ = new Subject<any>();
176179
private _data = [];
@@ -894,7 +897,14 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
894897
/**
895898
* @hidden @internal
896899
*/
897-
public searchValue = '';
900+
public get searchValue(): string {
901+
return this._searchValue;
902+
}
903+
904+
public set searchValue(val: string) {
905+
this.filterValue = val;
906+
this._searchValue = val;
907+
}
898908

899909
/**
900910
* @hidden @internal
@@ -1036,8 +1046,7 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
10361046
};
10371047
this.onSearchInput.emit(args);
10381048
if (args.cancel) {
1039-
this.searchValue = null;
1040-
return;
1049+
this.filterValue = null;
10411050
}
10421051
}
10431052
this.checkMatch();

0 commit comments

Comments
 (0)