Skip to content

Commit bb9019c

Browse files
authored
Merge pull request #12257 from IgniteUI/rivanova/fix-12245-master
fix(simple-combo): preserve selection on blur/tab when filtering the items - master
2 parents 6648247 + fd41350 commit bb9019c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,21 @@ describe('IgxSimpleCombo', () => {
895895
expect(combo.selection.length).toEqual(0);
896896
});
897897

898+
it('should not clear selection on tab/blur after filtering and selecting a value', () => {
899+
UIInteractions.simulateTyping('con', input);
900+
expect(combo.comboInput.value).toEqual('con');
901+
fixture.detectChanges();
902+
903+
UIInteractions.triggerKeyDownEvtUponElem('Enter', input.nativeElement);
904+
expect(combo.selection.length).toEqual(1);
905+
expect(combo.value).toEqual('Wisconsin');
906+
907+
UIInteractions.triggerEventHandlerKeyDown('Tab', input);
908+
fixture.detectChanges();
909+
expect(combo.selection.length).toEqual(1);
910+
expect(combo.value).toEqual('Wisconsin');
911+
});
912+
898913
it('should display the AddItem button when allowCustomValues is true and there is a partial match', fakeAsync(() => {
899914
fixture.componentInstance.allowCustomValues = true;
900915
fixture.detectChanges();
@@ -1118,7 +1133,7 @@ describe('IgxSimpleCombo', () => {
11181133

11191134
item1.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
11201135
fixture.detectChanges();
1121-
expect(combo.value).toBe(null);
1136+
expect(combo.value).toBe('');
11221137

11231138
combo.open();
11241139
fixture.detectChanges();
@@ -1145,7 +1160,7 @@ describe('IgxSimpleCombo', () => {
11451160

11461161
item5.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
11471162
fixture.detectChanges();
1148-
expect(combo.value).toBe(undefined);
1163+
expect(combo.value).toBe('');
11491164
});
11501165

11511166
it('should select falsy values except "undefined"', () => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
439439
argsSelection = Array.isArray(argsSelection) ? argsSelection : [argsSelection];
440440
this.selectionService.select_items(this.id, argsSelection, true);
441441
if (this._updateInput) {
442-
this.comboInput.value = this._internalFilter = this._value = displayText !== args.displayText
442+
this.comboInput.value = this._internalFilter = this._value = this.searchValue = displayText !== args.displayText
443443
? args.displayText
444444
: this.createDisplayText(argsSelection, [args.oldSelection]);
445445
}
@@ -457,7 +457,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
457457

458458
if (this.displayKey !== null && this.displayKey !== undefined
459459
&& newSelection.length > 0) {
460-
return this.convertKeysToItems(newSelection).map(e => e[this.displayKey])[0];
460+
return this.convertKeysToItems(newSelection).map(e => e[this.displayKey])[0]?.toString() || '';
461461
}
462462

463463
return newSelection[0]?.toString() || '';

0 commit comments

Comments
 (0)