Skip to content

Commit

Permalink
Merge pull request #517 from tatermelon/combo-selection
Browse files Browse the repository at this point in the history
Issue 495; Select item on blur
  • Loading branch information
jnurthen authored Nov 3, 2017
2 parents fa74668 + a5eb69b commit 78739db
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/combobox/aria1.1pattern/js/listbox-combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ aria.ListboxCombobox.prototype.setupEvents = function () {
this.input.addEventListener('keyup', this.checkKey.bind(this));
this.input.addEventListener('keydown', this.setActiveItem.bind(this));
this.input.addEventListener('focus', this.checkShow.bind(this));
this.input.addEventListener('blur', this.checkSelection.bind(this));
this.listbox.addEventListener('click', this.clickItem.bind(this));
};

Expand Down Expand Up @@ -152,6 +153,7 @@ aria.ListboxCombobox.prototype.setActiveItem = function (evt) {
this.selectItem(activeItem);
return;
case aria.KeyCode.TAB:
this.checkSelection();
this.hideListbox();
return;
default:
Expand Down Expand Up @@ -229,6 +231,14 @@ aria.ListboxCombobox.prototype.hideListbox = function () {
this.onHide();
};

aria.ListboxCombobox.prototype.checkSelection = function () {
if (this.activeIndex < 0) {
return;
}
var activeItem = this.getItemAt(this.activeIndex);
this.selectItem(activeItem);
};

aria.ListboxCombobox.prototype.autocompleteItem = function () {
var autocompletedItem = this.listbox.querySelector('.focused');
var inputText = this.input.value;
Expand Down

0 comments on commit 78739db

Please sign in to comment.