Skip to content

Commit

Permalink
fix(navigation): close dropdown on tab click fixes #58 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
varnastadeus authored and anjmao committed Oct 3, 2017
1 parent 0fa10fd commit e2fa1ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/lib/src/ng-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ describe('NgSelectComponent', function () {
expect(fixture.componentInstance.select.isOpen).toBeFalsy()
});

it('should close dropdown when there are no items', fakeAsync(() => {
fixture.componentInstance.select.onFilter({ target: { value: 'random stuff' } });
tick(200);
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Space);
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Tab);
expect(fixture.componentInstance.select.isOpen).toBeFalsy()
}));

it('should close dropdown when marked item is already selected', () => {
fixture.componentInstance.selectedCity = fixture.componentInstance.cities[0];
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Space);
Expand Down
8 changes: 6 additions & 2 deletions src/lib/src/ng-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,12 @@ export class NgSelectComponent implements OnInit, OnDestroy, ControlValueAccesso

private handleTab($event: KeyboardEvent) {
if (this.isOpen) {
this.select(this.itemsList.markedItem);
if (this.multiple) {
const marked = this.itemsList.markedItem;
if (marked) {
this.select(marked);
}

if (this.multiple || !marked) {
this.close();
}
}
Expand Down

0 comments on commit e2fa1ed

Please sign in to comment.