Commit 05e262bf authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview componentization: Add a timeout on search fields

Add a timeout so that the list does not immediately begin changing.
This will better match the behavior of the old UI.

Bug: 773928
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I5c9d3c3ff2ccd48b30dbb8ef34a86aceb3cbee3a
Reviewed-on: https://chromium-review.googlesource.com/1007895Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550090}
parent 06dc606f
......@@ -25,6 +25,12 @@ Polymer({
'search-changed': 'onSearchChanged_',
},
/**
* Timeout used to delay processing of the input, in ms.
* @private {?number}
*/
timeout_: null,
/** @return {!HTMLInputElement} */
getSearchInput: function() {
return this.$.searchInput;
......@@ -32,11 +38,17 @@ Polymer({
/**
* @param {!CustomEvent} e Event containing the new search.
* @private
*/
onSearchChanged_: function(e) {
const safeQuery = e.detail.trim().replace(SANITIZE_REGEX, '\\$&');
this.searchQuery =
safeQuery.length > 0 ? new RegExp(`(${safeQuery})`, 'i') : null;
let safeQuery = e.detail.trim().replace(SANITIZE_REGEX, '\\$&');
safeQuery = safeQuery.length > 0 ? new RegExp(`(${safeQuery})`, 'i') : null;
if (this.timeout_)
clearTimeout(this.timeout_);
this.timeout_ = setTimeout(() => {
this.searchQuery = safeQuery;
this.timeout_ = null;
}, 150);
},
});
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment