Skip to content

Commit

Permalink
Merge pull request #24 from jimutt/enable_keyboard_nav
Browse files Browse the repository at this point in the history
Enable usage of tab to focus next element after selection
  • Loading branch information
tristen authored Mar 7, 2019
2 parents bc1c7c5 + a693344 commit 5cbd4f4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/suggestions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ List.prototype.isEmpty = function() {
return !this.items.length;
};

List.prototype.isVisible = function() {
return this.element.style.display === 'block';
};

List.prototype.draw = function() {
this.element.innerHTML = '';

Expand Down
6 changes: 4 additions & 2 deletions src/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ Suggestions.prototype.handleKeyUp = function(keyCode) {
Suggestions.prototype.handleKeyDown = function(e) {
switch (e.keyCode) {
case 13: // ENTER
case 9: // TAB
e.preventDefault();
case 9: // TAB
if (!this.list.isEmpty()) {
if (this.list.isVisible()) {
e.preventDefault();
}
this.value(this.list.items[this.list.active].original);
this.list.hide();
}
Expand Down

0 comments on commit 5cbd4f4

Please sign in to comment.