Skip to content

Commit 64905bf

Browse files
committed
feat(combo): close dropdown on 'Tab'
1 parent c71bc6e commit 64905bf

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

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,16 @@ describe('igxCombo', () => {
19381938
fixture.detectChanges();
19391939
expect(firstVisibleItem.classList.contains(CSS_CLASS_FOCUSED)).toBeTruthy();
19401940
}));
1941+
it('should close the dropdown list on pressing Tab key', fakeAsync(() => {
1942+
combo.toggle();
1943+
fixture.detectChanges();
1944+
1945+
const dropdownContent = fixture.debugElement.query(By.css(`.${CSS_CLASS_CONTENT}`));
1946+
UIInteractions.triggerEventHandlerKeyDown('Tab', dropdownContent);
1947+
tick();
1948+
fixture.detectChanges();
1949+
expect(combo.collapsed).toBeTruthy();
1950+
}));
19411951
});
19421952
describe('primitive data dropdown: ', () => {
19431953
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
@@ -1191,6 +1191,17 @@ describe('IgxSimpleCombo', () => {
11911191
expect(combo.selection).toBeDefined()
11921192
});
11931193

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

0 commit comments

Comments
 (0)