Skip to content

Commit ef12b18

Browse files
authored
Merge pull request #16940 from IgniteUI/ganastasov/fix-16897-21.0.x
fix(simple-combo): prevent simple combo from clearing on blur - 21.0.x
2 parents b10fc2c + 975e72a commit ef12b18

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,34 @@ describe('IgxSimpleCombo', () => {
21032103

21042104
expect(document.activeElement).not.toBe(input.nativeElement);
21052105
}));
2106+
2107+
it('should sync searchValue/filterValue on writeValue and keep selection on blur', fakeAsync(() => {
2108+
combo.searchValue = combo.filterValue = 'zzz';
2109+
2110+
combo.writeValue('Connecticut');
2111+
tick();
2112+
fixture.detectChanges();
2113+
2114+
expect(combo.displayValue).toEqual('Connecticut');
2115+
expect(combo.searchValue).toEqual('Connecticut');
2116+
expect(combo.filterValue).toEqual('Connecticut');
2117+
2118+
combo.close();
2119+
tick();
2120+
fixture.detectChanges();
2121+
2122+
input.triggerEventHandler('focus', {});
2123+
fixture.detectChanges();
2124+
2125+
UIInteractions.triggerEventHandlerKeyDown('Tab', input);
2126+
tick();
2127+
fixture.detectChanges();
2128+
2129+
expect(combo.selection).toBeDefined();
2130+
expect(combo.selection.field).toEqual('Connecticut');
2131+
expect(combo.displayValue).toEqual('Connecticut');
2132+
expect(input.nativeElement.value).toEqual('Connecticut');
2133+
}));
21062134
});
21072135

21082136
describe('Form control tests: ', () => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
187187
this.cdr.markForCheck();
188188
this._displayValue = this.createDisplayText(super.selection, oldSelection);
189189
this._value = this.valueKey ? super.selection.map(item => item[this.valueKey]) : super.selection;
190-
this.filterValue = this._displayValue?.toString() || '';
190+
this.searchValue = this.filterValue = this._displayValue?.toString() || '';
191191
}
192192

193193
/** @hidden @internal */

0 commit comments

Comments
 (0)