Skip to content

Commit

Permalink
feat: add debounce function to improve filter performance (#17)
Browse files Browse the repository at this point in the history
* feat: add debounce function to improve filter performance

* feat: change input type to search
  • Loading branch information
stefanmomm authored Jun 6, 2024
1 parent 05490f5 commit c2f4de9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions assets/js/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="acf-svg-icon-picker__popup">
<a class="acf-svg-icon-picker__popup__close" href="javascript:">close</a>
<h4 class="acf-svg-icon-picker__popup__title">ACF Icon Picker - Choose icon</h4>
<input class="acf-svg-icon-picker__filter" type="text" id="filterIcons" placeholder="Start typing to filter icons" />
<input class="acf-svg-icon-picker__filter" type="search" id="filterIcons" placeholder="Start typing to filter icons" />
${list}
</div>
</div>`
Expand Down Expand Up @@ -161,9 +161,17 @@
setListHeight();
}

function debounce(func, wait) {
var timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}

iconsFilter.focus();

iconsFilter.addEventListener('keyup', displayResults);
iconsFilter.addEventListener('keyup', debounce(displayResults, 300));

// Closing
jQuery('.acf-svg-icon-picker__popup__close').on('click', function (e) {
Expand Down

0 comments on commit c2f4de9

Please sign in to comment.