Skip to content

Commit ee21e6b

Browse files
authored
Merge pull request #4689 from IgniteUI/nrobakova/fix-issue-4612
Close filter condition dropdownon on tab key pressed
2 parents 6aabba1 + 9bbb6af commit ee21e6b

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

projects/igniteui-angular/src/lib/grids/filtering/grid-filtering-row.component.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
141141
@HostBinding('class.igx-grid__filtering-row')
142142
public cssClass = 'igx-grid__filtering-row';
143143

144-
constructor(public filteringService: IgxFilteringService, public element: ElementRef, public cdr: ChangeDetectorRef) {}
144+
constructor(public filteringService: IgxFilteringService, public element: ElementRef, public cdr: ChangeDetectorRef) { }
145145

146146
ngAfterViewInit() {
147147
this._conditionsOverlaySettings.outlet = this.column.grid.outletDirective;
@@ -216,14 +216,16 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
216216
* Event handler for keydown on the input group's prefix.
217217
*/
218218
public onPrefixKeyDown(event: KeyboardEvent) {
219-
if ((event.key === KEYS.ENTER || event.key === KEYS.SPACE || event.key === KEYS.SPACE_IE) &&
220-
this.dropDownConditions.collapsed) {
221-
this._conditionsOverlaySettings.positionStrategy.settings.target = this.inputGroupPrefix.nativeElement;
222-
this.dropDownConditions.toggle(this._conditionsOverlaySettings);
219+
if ((event.key === KEYS.ENTER || event.key === KEYS.SPACE || event.key === KEYS.SPACE_IE) && this.dropDownConditions.collapsed) {
220+
this.toggleConditionsDropDown(this.inputGroupPrefix.nativeElement);
223221
event.stopImmediatePropagation();
224-
} else if (event.key === KEYS.TAB && event.shiftKey) {
225-
event.preventDefault();
226-
event.stopPropagation();
222+
} else if (event.key === KEYS.TAB) {
223+
if (event.shiftKey) {
224+
event.preventDefault();
225+
event.stopPropagation();
226+
} else if (!this.dropDownConditions.collapsed) {
227+
this.toggleConditionsDropDown(this.inputGroupPrefix.nativeElement);
228+
}
227229
}
228230
}
229231

@@ -234,12 +236,8 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
234236
this.isKeyPressed = true;
235237

236238
if (this.column.dataType === DataType.Boolean) {
237-
if ((event.key === KEYS.ENTER || event.key === KEYS.SPACE || event.key === KEYS.SPACE_IE) &&
238-
this.dropDownConditions.collapsed) {
239-
this.toggleConditionsDropDown(this.inputGroupPrefix.nativeElement);
240-
event.stopPropagation();
241-
return;
242-
} else if ((event.key === KEYS.ESCAPE || event.key === KEYS.ESCAPE_IE) && !this.dropDownConditions.collapsed) {
239+
if (event.key === KEYS.ENTER || event.key === KEYS.SPACE || event.key === KEYS.SPACE_IE) {
240+
this.inputGroupPrefix.nativeElement.focus();
243241
this.toggleConditionsDropDown(this.inputGroupPrefix.nativeElement);
244242
event.stopPropagation();
245243
return;
@@ -250,10 +248,8 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
250248
if (this.isComposing) {
251249
return;
252250
}
253-
254251
this.commitInput();
255252
} else if (event.altKey && (event.key === KEYS.DOWN_ARROW || event.key === KEYS.DOWN_ARROW_IE)) {
256-
this.input.nativeElement.blur();
257253
this.inputGroupPrefix.nativeElement.focus();
258254
this.toggleConditionsDropDown(this.inputGroupPrefix.nativeElement);
259255
} else if (event.key === KEYS.ESCAPE || event.key === KEYS.ESCAPE_IE) {
@@ -299,7 +295,8 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
299295
* Event handler for input click event.
300296
*/
301297
public onInputClick() {
302-
if (this.column.dataType === DataType.Boolean) {
298+
if (this.column.dataType === DataType.Boolean && this.dropDownConditions.collapsed) {
299+
this.inputGroupPrefix.nativeElement.focus();
303300
this.toggleConditionsDropDown(this.inputGroupPrefix.nativeElement);
304301
}
305302
}

projects/igniteui-angular/src/lib/grids/grid/grid-filtering-ui.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,38 @@ describe('IgxGrid - Filtering Row UI actions', () => {
24952495
expect(dropdownList).toBeNull();
24962496
}));
24972497

2498+
it('should close \'conditions dropdown\' when navigate with Tab key', fakeAsync(() => {
2499+
const initialChips = fix.debugElement.queryAll(By.directive(IgxChipComponent));
2500+
const stringCellChip = initialChips[0].nativeElement;
2501+
2502+
// Click filter chip to show filter row
2503+
stringCellChip.click();
2504+
tick(100);
2505+
fix.detectChanges();
2506+
2507+
const filterUIRow = fix.debugElement.query(By.css(FILTER_UI_ROW));
2508+
const inputgroup = filterUIRow.query(By.css('igx-input-group'));
2509+
const prefix = inputgroup.query(By.css('igx-prefix'));
2510+
2511+
// Click prefix to open conditions dropdown
2512+
prefix.triggerEventHandler('click', {});
2513+
tick(100);
2514+
fix.detectChanges();
2515+
2516+
// Verify dropdown is opened
2517+
let dropdownList = fix.debugElement.query(By.css('div.igx-drop-down__list.igx-toggle'));
2518+
expect(dropdownList).not.toBeNull();
2519+
2520+
// Press Tab key
2521+
UIInteractions.triggerKeyDownEvtUponElem('Tab', prefix.nativeElement, true);
2522+
tick(100);
2523+
fix.detectChanges();
2524+
2525+
// Verify dropdown is closed
2526+
dropdownList = fix.debugElement.query(By.css('div.igx-drop-down__list.igx-toggle'));
2527+
expect(dropdownList).toBeNull();
2528+
}));
2529+
24982530
it('Should commit the input and new chip after picking date from calendar for filtering.', fakeAsync(() => {
24992531
// Click date filter chip to show filter row.
25002532
const filterCells = fix.debugElement.queryAll(By.directive(IgxGridFilteringCellComponent));

0 commit comments

Comments
 (0)