Skip to content

Commit 36aa757

Browse files
authored
Merge pull request #13609 from IgniteUI/sstoychev/combo-enter-issue-16.1
fix(simple-combo): only select with enter when dropdown is open - 16.1
2 parents 2b2a651 + 1689214 commit 36aa757

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[attr.aria-expanded]="!this.dropdown.collapsed" [attr.aria-controls]="this.dropdown.listId"
1818
[attr.aria-labelledby]="this.ariaLabelledBy || this.label?.id || this.placeholder"
1919
[attr.placeholder]="placeholder" [disabled]="disabled" [igxTextSelection]="!composing"
20-
(focus)="onFocus()" (input)="handleInputChange($event)" (click)="handleInputClick()"
20+
(input)="handleInputChange($event)" (click)="handleInputClick()"
2121
(keyup)="handleKeyUp($event)" (keydown)="handleKeyDown($event)" (blur)="onBlur()"/>
2222

2323
<ng-container ngProjectAs="igx-suffix">
@@ -62,7 +62,7 @@
6262
[tabindex]="dropdown.collapsed ? -1 : 0" [attr.id]="dropdown.id"
6363
[attr.aria-activedescendant]="this.activeDescendant"
6464
(focus)="dropdown.onFocus()" (keydown)="handleItemKeyDown($event)">
65-
<igx-combo-item [role]="item?.isHeader? 'group' : 'option'" [singleMode]="true"
65+
<igx-combo-item [role]="item?.isHeader? 'group' : 'option'" [singleMode]="true"
6666
[itemHeight]="itemHeight" (click)="handleItemClick()" *igxFor="let item of data
6767
| comboFiltering:filterValue:displayKey:filteringOptions:filterFunction
6868
| comboGrouping:groupKey:valueKey:groupSortingDirection;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ describe('IgxSimpleCombo', () => {
915915
});
916916

917917
it('should not clear selection on tab/blur after filtering and selecting a value', () => {
918+
combo.focusSearchInput();
918919
UIInteractions.simulateTyping('con', input);
919920
expect(combo.comboInput.value).toEqual('con');
920921
fixture.detectChanges();
@@ -1032,6 +1033,7 @@ describe('IgxSimpleCombo', () => {
10321033
}));
10331034

10341035
it('should select the first filtered item with Enter', () => {
1036+
combo.focusSearchInput();
10351037
UIInteractions.simulateTyping('con', input);
10361038
expect(combo.comboInput.value).toEqual('con');
10371039
fixture.detectChanges();

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
9494

9595
private _updateInput = true;
9696

97-
// stores the last filtered value - move to common?
98-
private _internalFilter = '';
99-
10097
private _collapsing = false;
10198

10299
/** @hidden @internal */
@@ -185,9 +182,9 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
185182
const oldSelection = this.selection;
186183
this.selectionService.select_items(this.id, this.isValid(value) ? [value] : [], true);
187184
this.cdr.markForCheck();
188-
this._displayValue = this.createDisplayText(this.selection, oldSelection);
189-
this._value = this.valueKey ? this.selection.map(item => item[this.valueKey]) : this.selection;
190-
this.filterValue = this._internalFilter = this._displayValue?.toString();
185+
this._displayValue = this.createDisplayText(super.selection, oldSelection);
186+
this._value = this.valueKey ? super.selection.map(item => item[this.valueKey]) : super.selection;
187+
this.filterValue = this._displayValue?.toString() || '';
191188
}
192189

193190
/** @hidden @internal */
@@ -225,7 +222,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
225222
if (this.composing) {
226223
this.comboInput.focus();
227224
}
228-
this._internalFilter = this.comboInput.value;
229225
});
230226
this.dropdown.closing.pipe(takeUntil(this.destroy$)).subscribe((args) => {
231227
if (args.cancel) {
@@ -239,9 +235,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
239235
}
240236
this.comboInput.focus();
241237
});
242-
this.dropdown.closed.pipe(takeUntil(this.destroy$)).subscribe(() => {
243-
this.filterValue = this._internalFilter = this.comboInput.value;
244-
});
245238

246239
// in reactive form the control is not present initially
247240
// and sets the selection to an invalid value in writeValue method
@@ -265,7 +258,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
265258
/** @hidden @internal */
266259
public override handleInputChange(event?: any): void {
267260
if (event !== undefined) {
268-
this.filterValue = this._internalFilter = this.searchValue = typeof event === 'string' ? event : event.target.value;
261+
this.filterValue = this.searchValue = typeof event === 'string' ? event : event.target.value;
269262
}
270263
this._onChangeCallback(this.searchValue);
271264
if (this.collapsed && this.comboInput.focused) {
@@ -309,7 +302,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
309302
this.close();
310303
// manually trigger text selection as it will not be triggered during editing
311304
this.textSelection.trigger();
312-
this.filterValue = this.getElementVal(filtered);
313305
return;
314306
}
315307
if (event.key === this.platformUtil.KEYMAP.BACKSPACE
@@ -364,11 +356,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
364356
super.onBlur();
365357
}
366358

367-
/** @hidden @internal */
368-
public onFocus(): void {
369-
this._internalFilter = this.comboInput.value || '';
370-
}
371-
372359
/** @hidden @internal */
373360
public getEditElement(): HTMLElement {
374361
return this.comboInput.nativeElement;
@@ -465,7 +452,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
465452
this.selectionService.select_items(this.id, argsSelection, true);
466453
this._value = argsSelection;
467454
if (this._updateInput) {
468-
this.comboInput.value = this._internalFilter = this._displayValue = this.searchValue = displayText !== args.displayText
455+
this.comboInput.value = this._displayValue = this.searchValue = displayText !== args.displayText
469456
? args.displayText
470457
: this.createDisplayText(this.selection, [args.oldSelection]);
471458
}
@@ -545,7 +532,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
545532

546533
private clear(): void {
547534
this.clearSelection(true);
548-
this.comboInput.value = this._internalFilter = this._displayValue = this.searchValue = '';
535+
this.comboInput.value = this._displayValue = this.searchValue = '';
549536
}
550537

551538
private isValid(value: any): boolean {

0 commit comments

Comments
 (0)