Skip to content

Commit

Permalink
fix: don't mark disabled while opening (#360)
Browse files Browse the repository at this point in the history
fixes #330
  • Loading branch information
varnastadeus committed Mar 15, 2018
1 parent 2b88868 commit b5998f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ng-select/items-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class ItemsList {
if (this._lastSelectedItem && indexOfLastSelected > -1) {
this._markedIndex = indexOfLastSelected;
} else {
this._markedIndex = markDefault ? 0 : -1;
this._markedIndex = markDefault ? this.filteredItems.findIndex(x => !x.disabled) : -1;
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/ng-select/ng-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,15 @@ describe('NgSelectComponent', function () {
expect(fixture.componentInstance.select.itemsList.markedItem).toEqual(jasmine.objectContaining(result));
});

it('should open dropdown and mark first not disabled item', fakeAsync(() => {
fixture.componentInstance.cities[0].disabled = true;
fixture.componentInstance.cities = [...fixture.componentInstance.cities];
tickAndDetectChanges(fixture);
const result = { value: fixture.componentInstance.cities[1] };
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Space);
expect(fixture.componentInstance.select.itemsList.markedItem).toEqual(jasmine.objectContaining(result));
}));

it('should open dropdown without marking first item', () => {
fixture.componentInstance.select.markFirst = false;
triggerKeyDownEvent(getNgSelectElement(fixture), KeyCode.Space);
Expand Down Expand Up @@ -2189,8 +2198,8 @@ class NgSelectBasicTestCmp {
disabled = false;
dropdownPosition = 'bottom';
citiesLoading = false;
cities = [
{ id: 1, name: 'Vilnius' },
cities: any[] = [
{ id: 1, name: 'Vilnius', disabled: false },
{ id: 2, name: 'Kaunas' },
{ id: 3, name: 'Pabrade' },
];
Expand Down

0 comments on commit b5998f6

Please sign in to comment.