Skip to content

Commit

Permalink
Merge pull request #1249 from ng-select/marked-fix
Browse files Browse the repository at this point in the history
fix: mark first item when last marked is filtered out
  • Loading branch information
varnastadeus committed Jul 4, 2019
2 parents f9393dd + e08a769 commit 9f61d89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ng-select/items-list.spec.ts
Expand Up @@ -454,6 +454,16 @@ describe('ItemsList', () => {
list.markSelectedOrDefault();
expect(list.markedIndex).toBe(13);
});

it('should mark first after last marked item was filtered out', () => {
list.markSelectedOrDefault(true);
list.markNextItem();
list.filter('item-0');
list.markSelectedOrDefault(true);
expect(list.markedIndex).toBe(0);
list.markNextItem();
expect(list.markedIndex).toBe(0);
});
});

function itemsListFactory(cmp: NgSelectComponent): ItemsList {
Expand Down
4 changes: 4 additions & 0 deletions src/ng-select/items-list.ts
Expand Up @@ -316,6 +316,10 @@ export class ItemsList {
return -1;
}

if (this._markedIndex > -1 && this.markedItem === undefined) {
return -1;
}

const selectedIndex = this._filteredItems.indexOf(this.lastSelectedItem);
if (this.lastSelectedItem && selectedIndex < 0) {
return -1;
Expand Down

0 comments on commit 9f61d89

Please sign in to comment.