Skip to content

Commit

Permalink
fix(simple-combo): retains selection on blur
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofdiamond5 committed Feb 28, 2022
1 parent cd67a9e commit 3be0cc9
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
public composing = false;

private _updateInput = true;

// stores the last filtered value - move to common?
private _internalFilter = '';

Expand All @@ -109,7 +110,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
this._searchValue = val;
}

private get selectedItem() {
private get selectedItem(): any {
return this.selectionService.get(this.id).values().next().value;
}

Expand Down Expand Up @@ -200,13 +201,13 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
this.filterValue = this.searchValue = this.comboInput.value;
return;
}
this._internalFilter = this.filterValue;
this.filterValue = this.searchValue = '';
});
this.dropdown.opened.pipe(takeUntil(this.destroy$)).subscribe(() => {
if (this.composing) {
this.comboInput.focus();
}
this._internalFilter = this.comboInput.value;
});
this.dropdown.closing.pipe(takeUntil(this.destroy$)).subscribe((args) => {
if (this.getEditElement() && !args.event) {
Expand Down Expand Up @@ -401,7 +402,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
argsSelection = Array.isArray(argsSelection) ? argsSelection : [argsSelection];
this.selectionService.select_items(this.id, argsSelection, true);
if (this._updateInput) {
this.comboInput.value = this._value = displayText !== args.displayText
this.comboInput.value = this._internalFilter = this._value = displayText !== args.displayText
? args.displayText
: this.createDisplayText(argsSelection, [args.oldSelection]);
}
Expand Down Expand Up @@ -437,7 +438,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
this.clearAndClose();
return;
}
if (this.isPartialMatch(filtered) || this.selectedItem !== this._internalFilter) {
if (this.isPartialMatch(filtered) || this.getElementVal(filtered) !== this._internalFilter) {
this.clearAndClose();
}
}
Expand All @@ -446,7 +447,11 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
return !!this._internalFilter && this._internalFilter.length !== this.getElementVal(filtered).length;
}

private getElementVal(element: any) {
private getElementVal(element: any): any | null {
if (!element) {
return null;
}

return this.displayKey ? element[this.displayKey] : element;
}

Expand Down

0 comments on commit 3be0cc9

Please sign in to comment.