Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search on keyup #2

Merged
merged 2 commits into from
Nov 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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