Skip to content

Commit

Permalink
Fix - Combo, Drop Down - Fix TAB key navigation - 6.2.x (#3206)
Browse files Browse the repository at this point in the history
* fix(igxCombo): fix combo and drop down navigation with TAB key, #3200

* fix(combo): focusing combo input highlights the first nav item in DD, #3200
  • Loading branch information
ViktorSlavov authored and rkaraivanov committed Dec 3, 2018
1 parent 5eb957f commit d47bf79
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
16 changes: 16 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 @@ -881,6 +881,22 @@ describe('igxCombo', () => {
});
});
});

it('Should properly get the first focusable item when focusing the component list', fakeAsync(() => {
const fixture = TestBed.createComponent(IgxComboInputTestComponent);
fixture.detectChanges();
const combo = fixture.componentInstance.combo;
spyOn(combo.dropdown, 'getFirstSelectableItem').and.callThrough();
combo.toggle();
tick();
fixture.detectChanges();
combo.searchInput.nativeElement.dispatchEvent(new KeyboardEvent('keypress', { key: 'Tab'}));
(<HTMLElement>document.getElementsByClassName('igx-combo__content')[0]).dispatchEvent(new Event('focus'));
tick();
fixture.detectChanges();
expect(combo.dropdown.getFirstSelectableItem).toHaveBeenCalledTimes(1);
expect((<HTMLElement>combo.dropdown.focusedItem.element.nativeElement).textContent.trim()).toEqual('Michigan');
}));
});


Expand Down
6 changes: 6 additions & 0 deletions projects/igniteui-angular/src/lib/drop-down/drop-down.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ export abstract class IgxDropDownBase implements OnInit, IToggleView {
this._focusedItem.isFocused = true;
}
}
/**
* @hidden
*/
public getFirstSelectableItem() {
return this.children.find(child => !child.isHeader && !child.disabled);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export class IgxDropDownItemNavigationDirective {
set target(target: IgxDropDownBase) {
this._target = target ? target : this.dropdown;
}
@HostListener('focus')
handleFocus() {
if ((<any>this.target).combo) {
this.target.focusedItem = this.target.getFirstSelectableItem();
this.target.focusedItem.isFocused = true;
}
}

/**
* @hidden
Expand All @@ -52,7 +59,7 @@ export class IgxDropDownItemNavigationDirective {
if (event) {
const key = event.key.toLowerCase();
if (!this.target.collapsed) { // If dropdown is opened
const navKeys = ['esc', 'escape', 'enter', 'tab', 'space', 'spacebar', ' ',
const navKeys = ['esc', 'escape', 'enter', 'space', 'spacebar', ' ',
'arrowup', 'up', 'arrowdown', 'down', 'home', 'end'];
if (navKeys.indexOf(key) === -1) { // If key has appropriate function in DD
return;
Expand All @@ -65,10 +72,10 @@ export class IgxDropDownItemNavigationDirective {
switch (key) {
case 'esc':
case 'escape':
// case 'tab':
this.onEscapeKeyDown(event);
break;
case 'enter':
case 'tab':
this.onEnterKeyDown(event);
break;
case 'space':
Expand Down

0 comments on commit d47bf79

Please sign in to comment.