Skip to content

Close dropdown on 'Tab' key on the drop down item - 18.2.x #15892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I
this.handleSpace();
break;
case DropDownActionKey.ESCAPE:
case DropDownActionKey.TAB:
this.close();
}
}
Expand Down
10 changes: 10 additions & 0 deletions projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1711,8 +1711,8 @@
combo.virtualScrollContainer.scrollTo(51);
await firstValueFrom(combo.virtualScrollContainer.chunkLoad);
fixture.detectChanges();
let items = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_DROPDOWNLISTITEM}`));

Check warning on line 1714 in projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

View workflow job for this annotation

GitHub Actions / run-tests (18.x)

'items' is never reassigned. Use 'const' instead

Check warning on line 1714 in projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

View workflow job for this annotation

GitHub Actions / run-tests (20.x)

'items' is never reassigned. Use 'const' instead
let lastItem = items[items.length - 1].componentInstance;

Check warning on line 1715 in projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

View workflow job for this annotation

GitHub Actions / run-tests (18.x)

'lastItem' is never reassigned. Use 'const' instead

Check warning on line 1715 in projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

View workflow job for this annotation

GitHub Actions / run-tests (20.x)

'lastItem' is never reassigned. Use 'const' instead
expect(lastItem).toBeDefined();
lastItem.clicked(mockClick);
fixture.detectChanges();
Expand Down Expand Up @@ -1939,6 +1939,16 @@
fixture.detectChanges();
expect(firstVisibleItem.classList.contains(CSS_CLASS_FOCUSED)).toBeTruthy();
}));
it('should close the dropdown list on pressing Tab key', fakeAsync(() => {
combo.toggle();
fixture.detectChanges();

const dropdownContent = fixture.debugElement.query(By.css(`.${CSS_CLASS_CONTENT}`));
UIInteractions.triggerEventHandlerKeyDown('Tab', dropdownContent);
tick();
fixture.detectChanges();
expect(combo.collapsed).toBeTruthy();
}));
});
describe('primitive data dropdown: ', () => {
it('should properly navigate with HOME/END keys when no virtScroll is necessary', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class IgxDropDownItemNavigationDirective implements IDropDownNavigationDi
const key = event.key.toLowerCase();
if (!this.target.collapsed) { // If dropdown is opened
const navKeys = ['esc', 'escape', 'enter', 'space', 'spacebar', ' ',
'arrowup', 'up', 'arrowdown', 'down', 'home', 'end'];
'arrowup', 'up', 'arrowdown', 'down', 'home', 'end', 'tab'];
if (navKeys.indexOf(key) === -1) { // If key has appropriate function in DD
return;
}
Expand Down Expand Up @@ -98,6 +98,9 @@ export class IgxDropDownItemNavigationDirective implements IDropDownNavigationDi
case 'end':
this.onEndKeyDown();
break;
case 'tab':
this.target.onItemActionKey(DropDownActionKey.TAB, event);
break;
default:
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export abstract class IgxDropDownBaseDirective implements IDropDownList, OnInit
this.selectItem(this.focusedItem, event);
break;
case DropDownActionKey.ESCAPE:
case DropDownActionKey.TAB:
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export enum Navigate {
export const DropDownActionKey = /*@__PURE__*/mkenum({
ESCAPE: 'escape',
ENTER: 'enter',
SPACE: 'space'
SPACE: 'space',
TAB: 'tab',
});
export type DropDownActionKey = (typeof DropDownActionKey)[keyof typeof DropDownActionKey];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,17 @@ describe('IgxSimpleCombo', () => {
expect(combo.selection).toBeDefined()
});

it('should close the dropdown list on pressing Tab key', fakeAsync(() => {
combo.open();
fixture.detectChanges();

const dropdownContent = fixture.debugElement.query(By.css(`.${CSS_CLASS_CONTENT}`));
UIInteractions.triggerEventHandlerKeyDown('Tab', dropdownContent);
tick();
fixture.detectChanges();
expect(combo.collapsed).toBeTruthy();
}));

it('should clear the selection on tab/blur if the search text does not match any value', () => {
// allowCustomValues does not matter
combo.select(combo.data[2][combo.valueKey]);
Expand Down
Loading