Skip to content

Commit

Permalink
fix(multiselect): allow to clear item even no items available (#251)
Browse files Browse the repository at this point in the history
fixes #247
  • Loading branch information
varnastadeus committed Feb 10, 2018
1 parent cc8607a commit fb7b94b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/ng-select/ng-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,26 @@ describe('NgSelectComponent', function () {
tick();
}));

it('should clear item even if there are no items loaded', fakeAsync(() => {
const fixture = createTestingModule(
NgSelectBasicTestCmp,
`<ng-select [items]="cities"
bindLabel="name"
[(ngModel)]="selectedCity">
</ng-select>`);

selectOption(fixture, KeyCode.ArrowDown, 0);
fixture.detectChanges();
expect(fixture.componentInstance.select.selectedItems.length).toBe(1);
const selected = fixture.componentInstance.selectedCity;
fixture.componentInstance.cities = [];
fixture.detectChanges();

fixture.componentInstance.select.clearItem(selected)
expect(fixture.componentInstance.select.selectedItems.length).toBe(0);
tick();
}));

it('should display custom dropdown option template', async(() => {
const fixture = createTestingModule(
NgSelectBasicTestCmp,
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 @@ -128,7 +128,7 @@ export class NgSelectComponent implements OnInit, OnDestroy, OnChanges, AfterVie
private _disposeDocumentResizeListener = () => { };

clearItem = (item: any) => {
const option = this.itemsList.items.find(x => x.value === item);
const option = this.selectedItems.find(x => x.value === item);
this.unselect(option);
};

Expand Down

0 comments on commit fb7b94b

Please sign in to comment.