Skip to content

Commit

Permalink
fix: don't show not found text while loading (#252)
Browse files Browse the repository at this point in the history
fixes #243
  • Loading branch information
varnastadeus committed Feb 10, 2018
1 parent fb7b94b commit 6be231a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/ng-select/ng-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ describe('NgSelectComponent', function () {
NgSelectBasicTestCmp,
`<ng-select [items]="cities"
bindLabel="name"
[loading]="citiesLoading"
[multiple]="multiple"
[(ngModel)]="selectedCity">
</ng-select>`);
Expand All @@ -539,6 +540,17 @@ describe('NgSelectComponent', function () {
expect(text).toContain('No items found');
}));

it('should open dropdown with loading message', fakeAsync(() => {
fixture.componentInstance.cities = [];
fixture.componentInstance.citiesLoading = true;
tickAndDetectChanges(fixture);
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Space);
tickAndDetectChanges(fixture);
const options = fixture.debugElement.queryAll(By.css('.ng-option'));
expect(options.length).toBe(1);
expect(options[0].nativeElement.innerHTML).toContain('Loading...');
}));

it('should open dropdown and mark first item', () => {
const result = { value: fixture.componentInstance.cities[0] };
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Space);
Expand Down Expand Up @@ -1493,6 +1505,7 @@ class NgSelectBasicTestCmp {
selectedCity: { id: number; name: string };
multiple = false;
dropdownPosition = 'bottom';
citiesLoading = false;
cities = [
{ id: 1, name: 'Vilnius' },
{ id: 2, name: 'Kaunas' },
Expand Down
2 changes: 1 addition & 1 deletion src/ng-select/ng-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export class NgSelectComponent implements OnInit, OnDestroy, OnChanges, AfterVie

showNoItemsFound() {
const empty = this.itemsList.filteredItems.length === 0;
return (empty && !this._isTypeahead) ||
return (empty && !this._isTypeahead && !this.loading) ||
(empty && this._isTypeahead && this.filterValue && !this.isLoading);
}

Expand Down

0 comments on commit 6be231a

Please sign in to comment.