Skip to content

Commit

Permalink
fix(core): combobox communicateByObject bugs (#12815)
Browse files Browse the repository at this point in the history
* fix(core): only trigger onChange when matching object is found

* fix(core): fix bug where selecting item via click would not properly select if there are matching displayed names

* fix(core): fix match object via typing and unit tests
  • Loading branch information
mikerodonnell89 authored Jan 8, 2025
1 parent 3152649 commit 26fd691
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
19 changes: 14 additions & 5 deletions libs/core/combobox/combobox.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ describe('ComboboxComponent', () => {

it('should handle wrong input entry on dropdown mode', () => {
jest.spyOn(component, 'onChange');
component.communicateByObject = true;
component.displayFn = (item: any): string => {
if (item) {
return item.displayedValue;
Expand All @@ -91,6 +90,20 @@ describe('ComboboxComponent', () => {
expect(component.onChange).toHaveBeenCalledWith('otherDisplayedValue');
});

it('should not call onChange when using wrong input entry on dropdown mode with communicateByObject', () => {
jest.spyOn(component, 'onChange');
component.communicateByObject = true;
component.displayFn = (item: any): string => {
if (item) {
return item.displayedValue;
} else {
return '';
}
};
component.inputText = 'otherDisplayedValue';
expect(component.onChange).not.toHaveBeenCalled();
});

it('should handle write value from outside on dropdown mode', () => {
component.communicateByObject = true;
component.displayFn = (item: any): string => item.displayedValue;
Expand Down Expand Up @@ -342,8 +355,6 @@ describe('ComboboxComponent', () => {

component.displayFn = (product: Product): string => product?.name ?? '';

component.communicateByObject = true;

component.dropdownValues = allProducts;

component.groupFn = (products: Product[]) => {
Expand All @@ -369,8 +380,6 @@ describe('ComboboxComponent', () => {

component.displayFn = (product: Product): string => product?.name ?? '';

component.communicateByObject = true;

component.dropdownValues = allProducts;

component.groupFn = (products: Product[]) => {
Expand Down
5 changes: 4 additions & 1 deletion libs/core/combobox/combobox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,10 @@ export class ComboboxComponent<T = any>
} else if (values.length === 0) {
this.setValue(this.inputText);
}
this.onChange(this.getValue());
const thisValue = this.getValue();
if (typeof thisValue === 'object') {
this.onChange(thisValue);
}
} else {
this.onChange(this.inputText);
}
Expand Down

0 comments on commit 26fd691

Please sign in to comment.