Skip to content

Commit ea24646

Browse files
Merge pull request #15872 from IgniteUI/mkirkova/feat-combo-close-on-blur-15838-master
Close dropdown on 'Tab' key on the drop down item - 20.0.x
2 parents df8004e + 8d6e54d commit ea24646

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I
177177
this.handleSpace();
178178
break;
179179
case DropDownActionKey.ESCAPE:
180+
case DropDownActionKey.TAB:
180181
this.close();
181182
}
182183
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,16 @@ describe('igxCombo', () => {
19431943
fixture.detectChanges();
19441944
expect(firstVisibleItem.classList.contains(CSS_CLASS_FOCUSED)).toBeTruthy();
19451945
}));
1946+
it('should close the dropdown list on pressing Tab key', fakeAsync(() => {
1947+
combo.toggle();
1948+
fixture.detectChanges();
1949+
1950+
const dropdownContent = fixture.debugElement.query(By.css(`.${CSS_CLASS_CONTENT}`));
1951+
UIInteractions.triggerEventHandlerKeyDown('Tab', dropdownContent);
1952+
tick();
1953+
fixture.detectChanges();
1954+
expect(combo.collapsed).toBeTruthy();
1955+
}));
19461956
});
19471957
describe('primitive data dropdown: ', () => {
19481958
it('should properly navigate with HOME/END keys when no virtScroll is necessary', async () => {

projects/igniteui-angular/src/lib/drop-down/drop-down-navigation.directive.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class IgxDropDownItemNavigationDirective implements IDropDownNavigationDi
6262
const key = event.key.toLowerCase();
6363
if (!this.target.collapsed) { // If dropdown is opened
6464
const navKeys = ['esc', 'escape', 'enter', 'space', 'spacebar', ' ',
65-
'arrowup', 'up', 'arrowdown', 'down', 'home', 'end'];
65+
'arrowup', 'up', 'arrowdown', 'down', 'home', 'end', 'tab'];
6666
if (navKeys.indexOf(key) === -1) { // If key has appropriate function in DD
6767
return;
6868
}
@@ -98,6 +98,9 @@ export class IgxDropDownItemNavigationDirective implements IDropDownNavigationDi
9898
case 'end':
9999
this.onEndKeyDown();
100100
break;
101+
case 'tab':
102+
this.target.onItemActionKey(DropDownActionKey.TAB, event);
103+
break;
101104
default:
102105
return;
103106
}

projects/igniteui-angular/src/lib/drop-down/drop-down.base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export abstract class IgxDropDownBaseDirective implements IDropDownList, OnInit
196196
this.selectItem(this.focusedItem, event);
197197
break;
198198
case DropDownActionKey.ESCAPE:
199+
case DropDownActionKey.TAB:
199200
}
200201
}
201202

projects/igniteui-angular/src/lib/drop-down/drop-down.common.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export enum Navigate {
1313
export const DropDownActionKey = {
1414
ESCAPE: 'escape',
1515
ENTER: 'enter',
16-
SPACE: 'space'
16+
SPACE: 'space',
17+
TAB: 'tab'
1718
} as const;
1819
export type DropDownActionKey = (typeof DropDownActionKey)[keyof typeof DropDownActionKey];
1920

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,17 @@ describe('IgxSimpleCombo', () => {
11961196
expect(combo.selection).toBeDefined()
11971197
});
11981198

1199+
it('should close the dropdown list on pressing Tab key', fakeAsync(() => {
1200+
combo.open();
1201+
fixture.detectChanges();
1202+
1203+
const dropdownContent = fixture.debugElement.query(By.css(`.${CSS_CLASS_CONTENT}`));
1204+
UIInteractions.triggerEventHandlerKeyDown('Tab', dropdownContent);
1205+
tick();
1206+
fixture.detectChanges();
1207+
expect(combo.collapsed).toBeTruthy();
1208+
}));
1209+
11991210
it('should clear the selection on tab/blur if the search text does not match any value', () => {
12001211
// allowCustomValues does not matter
12011212
combo.select(combo.data[2][combo.valueKey]);

0 commit comments

Comments
 (0)