Skip to content
Snippets Groups Projects
Unverified Commit fb6464b7 authored by Felix Eckhofer's avatar Felix Eckhofer :man_dancing:
Browse files

Debounce filter so it feels snappier

parent a7ad602e
No related branches found
No related tags found
No related merge requests found
import { Controller } from "@hotwired/stimulus";
function debounce(func, wait) {
let timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}
export default class extends Controller {
static targets = ["input", "list"];
connect() {
//this.options = Array.from(this.listTarget.children)
this.filter = debounce(this.filter_nodebounce.bind(this), 300);
}
filter() {
const query = this.inputTarget.value.toLowerCase()
filter_nodebounce() {
const query = this.inputTarget.value.toLowerCase();
// Filter options by the `data-filteredlist-match` attribute
for (const option of this.listTarget.children) {
if (option.dataset.filteredlistMatch.includes(query)) {
option.classList.remove("hidden")
option.classList.remove("hidden");
} else {
option.classList.add("hidden")
option.classList.add("hidden");
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment