Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #47 from adrian-enspired/search-on-keyup
Browse files Browse the repository at this point in the history
Search and Destroy
  • Loading branch information
Mobius1 authored Nov 9, 2017
2 parents 141be57 + 3003348 commit bcb6c90
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/selectr.js
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@
return;
}

// Open the dropdown on [enter], [↓], and [↑] keys
// Open the dropdown on [enter], [ ], [↓], and [↑] keys
if (
e.key === " " ||
(! that.opened && ["Enter", "ArrowUp", "ArrowDown"].indexOf(e.key) > -1)
Expand Down Expand Up @@ -1373,9 +1373,22 @@
window.addEventListener("resize", this.update);
window.addEventListener("scroll", this.update);

// remove event listeners on destroy()
this.on('selectr.destroy', function () {
document.removeEventListener("click", this.events.dismiss);
window.removeEventListener("keydown", this.events.navigate);
window.removeEventListener("resize", this.update);
window.removeEventListener("scroll", this.update);
});

// Listen for form.reset() (@ambrooks, #13)
if (this.el.form) {
this.el.form.addEventListener("reset", this.events.reset);

// remove listener on destroy()
this.on('selectr.destroy', function () {
this.el.form.removeEventListener("reset", this.events.reset);
});
}
};

Expand Down Expand Up @@ -1469,17 +1482,6 @@
// Remove the className from select element
util.removeClass(this.el, 'selectr-hidden');

// Remove reset listener from parent form
if (this.el.form) {
util.off(this.el.form, "reset", this.events.reset);
}

// Remove event listeners attached to doc and win
util.off(document, "click", this.events.dismiss);
util.off(document, "keydown", this.events.navigate);
util.off(window, "resize", this.update);
util.off(window, "scroll", this.update);

// Replace the container with the original select element
this.container.parentNode.replaceChild(this.el, this.container);

Expand Down Expand Up @@ -1883,7 +1885,7 @@
// Check the options for the matching string
util.each(this.options, function(i, option) {
var item = this.items[option.idx];
var matches = compare( option.textContent.toLowerCase(), string );
var matches = compare( option.textContent.trim().toLowerCase(), string );

if ( matches && !option.disabled ) {

Expand Down

0 comments on commit bcb6c90

Please sign in to comment.