Skip to content

Commit

Permalink
feat: open dropdown on enter
Browse files Browse the repository at this point in the history
closes #508
  • Loading branch information
varnastadeus committed May 1, 2018
1 parent bcf3340 commit aeed111
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ng-select/ng-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,20 @@ describe('NgSelectComponent', function () {
expect(findByLabel).toHaveBeenCalledWith('vil')
}));
});

describe('enter', () => {
it('should open dropdown when it is closed', () => {
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Enter);
expect(select.isOpen).toBe(true);
});

it('should select option and close dropdown', () => {
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Space);
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Enter);
expect(select.selectedItems[0].value).toEqual(fixture.componentInstance.cities[0])
expect(select.isOpen).toBe(false);
});
});
});

describe('Outside click', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/ng-select/ng-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
} else if (this.addTag) {
this.selectTag();
}
} else {
this.open();
}
$event.preventDefault();
$event.stopPropagation();
Expand Down

0 comments on commit aeed111

Please sign in to comment.