Skip to content

Commit

Permalink
fix: show type to search on typeahead (#416)
Browse files Browse the repository at this point in the history
fixes #405
  • Loading branch information
anjmao committed Apr 6, 2018
1 parent aff8468 commit ed1b3d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions demo/app/examples/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { DataService, Person } from '../shared/data.service';
bindLabel="name"
[addTag]="true"
[multiple]="true"
[hideSelected]="true"
[typeahead]="peopleTypeahead"
[(ngModel)]="selectedPersons">
</ng-select>
Expand Down
12 changes: 12 additions & 0 deletions src/ng-select/ng-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,7 @@ describe('NgSelectComponent', function () {
`<ng-select [items]="cities"
[typeahead]="filter"
bindLabel="name"
[hideSelected]="hideSelected"
[(ngModel)]="selectedCity">
</ng-select>`);
});
Expand Down Expand Up @@ -1953,6 +1954,16 @@ describe('NgSelectComponent', function () {
tickAndDetectChanges(fixture);
expect(fixture.componentInstance.select.isLoading).toBeFalsy();
}));

it('should open dropdown when hideSelected=true and no items to select', fakeAsync(() => {
fixture.componentInstance.hideSelected = true;
fixture.componentInstance.cities = [];
fixture.componentInstance.selectedCity = null;
tickAndDetectChanges(fixture);
fixture.componentInstance.filter.subscribe();
fixture.componentInstance.select.open();
expect(fixture.componentInstance.select.isOpen).toBeTruthy();
}));
});
});

Expand Down Expand Up @@ -2366,6 +2377,7 @@ class NgSelectTestCmp {
filter = new Subject<string>();
searchFn: (term: string, item: any) => boolean = null;
selectOnTab = true;
hideSelected = false;

citiesLoading = false;
selectedCityId: number;
Expand Down
5 changes: 4 additions & 1 deletion src/ng-select/ng-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
}

open() {
if (this.isDisabled || this.isOpen || this.itemsList.maxItemsSelected || this.itemsList.noItemsToSelect) {
if (this.isDisabled || this.isOpen || this.itemsList.maxItemsSelected) {
return;
}
if (!this._isTypeahead && (this.itemsList.noItemsToSelect)) {
return;
}
this.isOpen = true;
Expand Down

0 comments on commit ed1b3d6

Please sign in to comment.