Skip to content

Commit dbc2e71

Browse files
fix(simple-combo): prevent simple combo from clearing on blur
1 parent 7446cf9 commit dbc2e71

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

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

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

22322232
expect(document.activeElement).not.toBe(input.nativeElement);
22332233
}));
2234+
2235+
it('should sync searchValue/filterValue on writeValue and keep selection on blur', fakeAsync(() => {
2236+
combo.searchValue = combo.filterValue = 'zzz';
2237+
2238+
combo.writeValue('Connecticut');
2239+
tick();
2240+
fixture.detectChanges();
2241+
2242+
expect(combo.displayValue).toEqual('Connecticut');
2243+
expect(combo.searchValue).toEqual('Connecticut');
2244+
expect(combo.filterValue).toEqual('Connecticut');
2245+
2246+
combo.close();
2247+
tick();
2248+
fixture.detectChanges();
2249+
2250+
input.triggerEventHandler('focus', {});
2251+
fixture.detectChanges();
2252+
2253+
UIInteractions.triggerEventHandlerKeyDown('Tab', input);
2254+
tick();
2255+
fixture.detectChanges();
2256+
2257+
expect(combo.selection).toBeDefined();
2258+
expect(combo.selection.field).toEqual('Connecticut');
2259+
expect(combo.displayValue).toEqual('Connecticut');
2260+
expect(input.nativeElement.value).toEqual('Connecticut');
2261+
}));
22342262
});
22352263

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
216216
this.cdr.markForCheck();
217217
this._displayValue = this.createDisplayText(super.selection, oldSelection);
218218
this._value = this.valueKey ? super.selection.map(item => item[this.valueKey]) : super.selection;
219-
this.filterValue = this._displayValue?.toString() || '';
219+
this.searchValue = this.filterValue = this._displayValue?.toString() || '';
220220
}
221221

222222
/** @hidden @internal */

0 commit comments

Comments
 (0)