Skip to content

Commit a38b03c

Browse files
committed
feat(combo): close dropdown on 'Tab'
1 parent e3f83b3 commit a38b03c

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
@@ -179,6 +179,7 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I
179179
this.handleSpace();
180180
break;
181181
case DropDownActionKey.ESCAPE:
182+
case DropDownActionKey.TAB:
182183
this.close();
183184
}
184185
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,16 @@ describe('igxCombo', () => {
19391939
fixture.detectChanges();
19401940
expect(firstVisibleItem.classList.contains(CSS_CLASS_FOCUSED)).toBeTruthy();
19411941
}));
1942+
it('should close the dropdown list on pressing Tab key', fakeAsync(() => {
1943+
combo.toggle();
1944+
fixture.detectChanges();
1945+
1946+
const dropdownContent = fixture.debugElement.query(By.css(`.${CSS_CLASS_CONTENT}`));
1947+
UIInteractions.triggerEventHandlerKeyDown('Tab', dropdownContent);
1948+
tick();
1949+
fixture.detectChanges();
1950+
expect(combo.collapsed).toBeTruthy();
1951+
}));
19421952
});
19431953
describe('primitive data dropdown: ', () => {
19441954
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 = /*@__PURE__*/mkenum({
1414
ESCAPE: 'escape',
1515
ENTER: 'enter',
16-
SPACE: 'space'
16+
SPACE: 'space',
17+
TAB: 'tab',
1718
});
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
@@ -1195,6 +1195,17 @@ describe('IgxSimpleCombo', () => {
11951195
expect(combo.selection).toBeDefined()
11961196
});
11971197

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

0 commit comments

Comments
 (0)