Skip to content

Commit 3e4298f

Browse files
committed
fix(simple-combo): Update the model value only if selection is changed
1 parent b61eaad commit 3e4298f

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,45 @@ describe('IgxSimpleCombo', () => {
18091809
expect(combo.valid).toEqual(IgxComboState.INVALID);
18101810
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);
18111811
});
1812+
1813+
it('Should update the model only if a selection is changing otherwise it should be undefiend when the user is filtering in templeted form', fakeAsync(() => {
1814+
input = fixture.debugElement.query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
1815+
let model;
1816+
1817+
combo.open();
1818+
fixture.detectChanges();
1819+
const item2 = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_DROPDOWNLISTITEM}`))[3];
1820+
item2.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
1821+
fixture.detectChanges();
1822+
model = fixture.componentInstance.values;
1823+
1824+
expect(combo.displayValue).toEqual(['Illinois']);
1825+
expect(combo.value).toEqual(['Illinois']);
1826+
expect(model).toEqual('Illinois');
1827+
1828+
combo.deselect();
1829+
fixture.detectChanges();
1830+
model = fixture.componentInstance.values;
1831+
1832+
expect(combo.selection).toEqual([]);
1833+
expect(model).toEqual(undefined);
1834+
expect(combo.displayValue).toEqual([]);
1835+
1836+
combo.focusSearchInput();
1837+
UIInteractions.simulateTyping('con', input);
1838+
fixture.detectChanges();
1839+
model = fixture.componentInstance.values;
1840+
expect(combo.comboInput.value).toEqual('con');
1841+
expect(model).toEqual(undefined);
1842+
1843+
UIInteractions.triggerKeyDownEvtUponElem('Enter', input.nativeElement);
1844+
fixture.detectChanges();
1845+
model = fixture.componentInstance.values;
1846+
expect(combo.selection).toBeDefined()
1847+
expect(combo.displayValue).toEqual(['Wisconsin']);
1848+
expect(combo.value).toEqual(['Wisconsin']);
1849+
expect(model).toEqual('Wisconsin');
1850+
}));
18121851
});
18131852
describe('Reactive form tests: ', () => {
18141853
beforeAll(waitForAsync(() => {
@@ -2027,6 +2066,44 @@ describe('IgxSimpleCombo', () => {
20272066
expect((combo as any).inputGroup.element.nativeElement.classList.contains(CSS_CLASS_INPUT_GROUP_REQUIRED)).toBe(false);
20282067
}));
20292068
});
2069+
2070+
it('Should update the model only if a selection is changing otherwise it should be undefiend when the user is filtering in reactive form', fakeAsync(() => {
2071+
const form = (fixture.componentInstance as IgxSimpleComboInReactiveFormComponent).comboForm;
2072+
input = fixture.debugElement.query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
2073+
2074+
combo.open();
2075+
fixture.detectChanges();
2076+
2077+
const item2 = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_DROPDOWNLISTITEM}`))[3];
2078+
item2.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
2079+
fixture.detectChanges();
2080+
2081+
2082+
expect(combo.displayValue).toEqual(['Four']);
2083+
expect(combo.value).toEqual([4]);
2084+
expect(form.controls['comboValue'].value).toEqual([4]);
2085+
2086+
combo.deselect();
2087+
fixture.detectChanges();
2088+
2089+
expect(combo.selection).toEqual([]);
2090+
expect(form.controls['comboValue'].value).toEqual(undefined);
2091+
expect(combo.displayValue).toEqual([]);
2092+
2093+
combo.focusSearchInput();
2094+
UIInteractions.simulateTyping('on', input);
2095+
fixture.detectChanges();
2096+
expect(combo.comboInput.value).toEqual('on');
2097+
expect(form.controls['comboValue'].value).toEqual(undefined);
2098+
2099+
combo.select(combo.data[0][combo.valueKey]);
2100+
fixture.detectChanges();
2101+
expect(combo.selection).toBeDefined();
2102+
expect(combo.displayValue).toEqual(['One']);
2103+
expect(combo.value).toEqual([1]);
2104+
expect(form.controls['comboValue'].value).toEqual(1);
2105+
}));
2106+
20302107
});
20312108

20322109
describe('Selection tests: ', () => {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
260260
if (event !== undefined) {
261261
this.filterValue = this.searchValue = typeof event === 'string' ? event : event.target.value;
262262
}
263-
this._onChangeCallback(this.searchValue);
264263
if (this.collapsed && this.comboInput.focused) {
265264
this.open();
266265
}

0 commit comments

Comments
 (0)