Skip to content

Commit

Permalink
fix: focus select after unselecting single item
Browse files Browse the repository at this point in the history
fixes #661
  • Loading branch information
varnastadeus committed Jul 30, 2018
1 parent cb64f45 commit 1bc3f02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/ng-select/ng-select.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2615,9 +2615,9 @@ describe('NgSelectComponent', function () {
expect(select.isOpen).toBe(false);
}));

it('should focus dropdown', fakeAsync(() => {
it('should focus dropdown while unselecting', fakeAsync(() => {
const focus = spyOn(select, 'focus');
triggerMousedown();
select.unselect(fixture.componentInstance.cities[0]);
tickAndDetectChanges(fixture);
expect(focus).toHaveBeenCalled();
}));
Expand Down
13 changes: 9 additions & 4 deletions src/ng-select/ng-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
return;
}

if (!this._focused) {
this.focus();
}

if (target.className.includes('ng-value-icon')) {
return;
}

if (!this._focused) {
this.focus();
}

if (this.searchable) {
this.open();
} else {
Expand Down Expand Up @@ -395,6 +395,7 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C

unselect(item: NgOption) {
this.itemsList.unselect(item);
this.focus();
this._updateNgModel();
this.removeEvent.emit(item);
}
Expand Down Expand Up @@ -453,6 +454,10 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C
}

onInputFocus($event) {
if (this._focused) {
return;
}

(<HTMLElement>this.elementRef.nativeElement).classList.add('ng-select-focused');
this.focusEvent.emit($event);
this._focused = true;
Expand Down

0 comments on commit 1bc3f02

Please sign in to comment.