Skip to content

Commit

Permalink
Merge pull request #14234 from IgniteUI/ikitanov/fix-14053-master
Browse files Browse the repository at this point in the history
Update the model value only if selection is changed
  • Loading branch information
kacheshmarova authored Jun 3, 2024
2 parents 4825aa0 + 478b0f6 commit 210d53e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ All notable changes for each version of this project will be documented in this
### General
- Removed deprecated property `displayDensity`. Size is now controlled only through the custom CSS property `--ig-size`. Refer to the [Update Guide](https://www.infragistics.com/products/ignite-ui-angular/angular/components/general/update-guide) and components documentation for usage details.

### General
- `IgxSimpleCombo`
- **Behavioral Change** When bound to `ngModel` and `formControlName` directives, the model would not be updated when the user types into the input and will only be updated on selection.

## 17.2.0
### New Features
- `IgxAvatar`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,45 @@ describe('IgxSimpleCombo', () => {
expect(combo.valid).toEqual(IgxInputState.INVALID);
expect(combo.comboInput.valid).toEqual(IgxInputState.INVALID);
});

it('Should update the model only if a selection is changing otherwise it shoudl be undefiend when the user is filtering in templeted form', fakeAsync(() => {
input = fixture.debugElement.query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));
let model;

combo.open();
fixture.detectChanges();
const item2 = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_DROPDOWNLISTITEM}`))[3];
item2.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
fixture.detectChanges();
model = fixture.componentInstance.values;

expect(combo.displayValue).toEqual('Illinois');
expect(combo.value).toEqual('Illinois');
expect(model).toEqual('Illinois');

combo.deselect();
fixture.detectChanges();
model = fixture.componentInstance.values;

expect(combo.selection).not.toBeDefined();
expect(model).toEqual(undefined);
expect(combo.displayValue).toEqual('');

combo.focusSearchInput();
UIInteractions.simulateTyping('con', input);
fixture.detectChanges();
model = fixture.componentInstance.values;
expect(combo.comboInput.value).toEqual('con');
expect(model).toEqual(undefined);

UIInteractions.triggerKeyDownEvtUponElem('Enter', input.nativeElement);
fixture.detectChanges();
model = fixture.componentInstance.values;
expect(combo.selection).toBeDefined()
expect(combo.displayValue).toEqual('Wisconsin');
expect(combo.value).toEqual('Wisconsin');
expect(model).toEqual('Wisconsin');
}));
});
describe('Reactive form tests: ', () => {
beforeAll(waitForAsync(() => {
Expand Down Expand Up @@ -2036,6 +2075,40 @@ describe('IgxSimpleCombo', () => {
expect((combo as any).inputGroup.element.nativeElement.classList.contains(CSS_CLASS_INPUT_GROUP_INVALID)).toBe(true);
expect((combo as any).inputGroup.element.nativeElement.classList.contains(CSS_CLASS_INPUT_GROUP_REQUIRED)).toBe(false);
}));

it('Should update the model only if a selection is changing otherwise it shoudl be undefiend when the user is filtering in reactive form', fakeAsync(() => {
const form = (fixture.componentInstance as IgxSimpleComboInReactiveFormComponent).comboForm;
input = fixture.debugElement.query(By.css(`.${CSS_CLASS_COMBO_INPUTGROUP}`));

combo.open();
fixture.detectChanges();
const item2 = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_DROPDOWNLISTITEM}`))[3];
item2.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
fixture.detectChanges();

expect(combo.displayValue).toEqual('Four');
expect(combo.value).toEqual(4);
expect(form.controls['comboValue'].value).toEqual(4);

combo.deselect();
fixture.detectChanges();

expect(combo.selection).not.toBeDefined()
expect(form.controls['comboValue'].value).toEqual(undefined);
expect(combo.displayValue).toEqual('');

combo.focusSearchInput();
UIInteractions.simulateTyping('on', input);
fixture.detectChanges();
expect(combo.comboInput.value).toEqual('on');
expect(form.controls['comboValue'].value).toEqual(undefined);

UIInteractions.triggerKeyDownEvtUponElem('Enter', input.nativeElement);
expect(combo.selection).toBeDefined()
expect(combo.displayValue).toEqual('One');
expect(combo.value).toEqual(1);
expect(form.controls['comboValue'].value).toEqual(1);
}));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
if (event !== undefined) {
this.filterValue = this.searchValue = typeof event === 'string' ? event : event.target.value;
}
this._onChangeCallback(this.searchValue);
if (this.collapsed && this.comboInput.focused) {
this.open();
}
Expand Down

0 comments on commit 210d53e

Please sign in to comment.