Skip to content

Commit 922cc09

Browse files
authored
feat(simple-combo): navigate to next filtered item on ArrowDown (#12686)
* feat(simple-combo): navigate to next filtered item on ArrowDown * chore(combo.common): add abstract onArrowDown method
1 parent 9c293ec commit 922cc09

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

projects/igniteui-angular/src/lib/combo/combo.common.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
EventEmitter,
99
forwardRef,
1010
HostBinding,
11-
HostListener,
1211
Inject,
1312
InjectionToken,
1413
Injector,
@@ -951,15 +950,6 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
951950
super(_displayDensityOptions);
952951
}
953952

954-
/** @hidden @internal */
955-
@HostListener('keydown.ArrowDown', ['$event'])
956-
@HostListener('keydown.Alt.ArrowDown', ['$event'])
957-
public onArrowDown(event: Event) {
958-
event.preventDefault();
959-
event.stopPropagation();
960-
this.open();
961-
}
962-
963953
/** @hidden @internal */
964954
public ngOnInit() {
965955
this.ngControl = this._injector.get<NgControl>(NgControl, null);
@@ -1322,6 +1312,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
13221312
public abstract set filteredData(val: any[] | null);
13231313

13241314
public abstract handleOpened();
1315+
public abstract onArrowDown(event: Event);
13251316
public abstract focusSearchInput(opening?: boolean);
13261317

13271318
public abstract select(newItem: any): void;

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CommonModule } from '@angular/common';
22
import {
33
AfterViewInit, ChangeDetectorRef, Component, ElementRef, NgModule, OnInit, OnDestroy,
4-
Optional, Inject, Injector, ViewChild, Input, Output, EventEmitter
4+
Optional, Inject, Injector, ViewChild, Input, Output, EventEmitter, HostListener
55
} from '@angular/core';
66
import {
77
IgxComboItemDirective,
@@ -202,6 +202,15 @@ export class IgxComboComponent extends IgxComboBaseDirective implements AfterVie
202202
this.comboAPI.register(this);
203203
}
204204

205+
/** @hidden @internal */
206+
@HostListener('keydown.ArrowDown', ['$event'])
207+
@HostListener('keydown.Alt.ArrowDown', ['$event'])
208+
public onArrowDown(event: Event) {
209+
event.preventDefault();
210+
event.stopPropagation();
211+
this.open();
212+
}
213+
205214
/** @hidden @internal */
206215
public get displaySearchInput(): boolean {
207216
return this.filteringOptions.filterable || this.allowCustomValues;

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

+16-3
Original file line numberDiff line numberDiff line change
@@ -1039,13 +1039,26 @@ describe('IgxSimpleCombo', () => {
10391039
expect(combo.comboInput.value).toEqual('con');
10401040
fixture.detectChanges();
10411041

1042-
UIInteractions.triggerKeyDownEvtUponElem('ArrowDown', input.nativeElement);
1043-
expect(document.activeElement).toHaveClass('igx-combo__content');
1044-
10451042
UIInteractions.triggerKeyDownEvtUponElem('Enter', input.nativeElement);
10461043
expect(input.nativeElement.value).toEqual('Wisconsin');
10471044
});
10481045

1046+
it('should navigate to next filtered item on ArrowDown', () => {
1047+
combo.allowCustomValues = true;
1048+
1049+
input.triggerEventHandler('focus', {});
1050+
fixture.detectChanges();
1051+
1052+
UIInteractions.simulateTyping('con', input);
1053+
expect(combo.comboInput.value).toEqual('con');
1054+
fixture.detectChanges();
1055+
1056+
// filtered data -> Wisconsin, Connecticut
1057+
UIInteractions.triggerKeyDownEvtUponElem('ArrowDown', input.nativeElement);
1058+
UIInteractions.triggerKeyDownEvtUponElem('Enter', input.nativeElement);
1059+
expect(input.nativeElement.value).toEqual('Connecticut');
1060+
});
1061+
10491062
it('should clear selection when all text in input is removed by Backspace and Delete', () => {
10501063
combo.select('Wisconsin');
10511064
fixture.detectChanges();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
140140
this.open();
141141
} else {
142142
if (this.virtDir.igxForOf.length > 0 && !this.selectedItem) {
143-
this.dropdown.navigateFirst();
143+
this.dropdown.navigateNext();
144144
this.dropdownContainer.nativeElement.focus();
145145
} else if (this.allowCustomValues) {
146146
this.addItem?.element.nativeElement.focus();

0 commit comments

Comments
 (0)