Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
fixed autofocus on empty input
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Aug 19, 2018
1 parent 102dbfd commit a211792
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ export class Suggestions {
event.preventDefault();

if (!this.closed) {
this.focus(this.focusedIndex + 1);
if (this.focusedIndex === undefined) {
this.focus(0);
} else {
this.focus(this.focusedIndex + 1);
}
} else if (this.element.value) {
this.open();
}
Expand Down Expand Up @@ -388,7 +392,12 @@ export class Suggestions {
this.closed = false;
this.element.classList.add('is-open');
this.input.dispatchEvent(new CustomEvent('suggestions:open'));
this.focused ? this.focused.focus() : this.focus(0);

if (this.focused) {
this.focused.focus();
} else if (this.input.value) {
this.focus(0);
}

return this;
}
Expand Down

0 comments on commit a211792

Please sign in to comment.