[New] clear search term without delay

This commit is contained in:
Robert von Burg 2022-04-20 09:37:52 +02:00
parent faabdbc2a0
commit b2d0366b29
2 changed files with 17 additions and 18 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "strolch-wc-debounced-input", "name": "strolch-wc-debounced-input",
"description": "Strolch WebComponent Debounced Input", "description": "Strolch WebComponent Debounced Input",
"version": "0.1.1", "version": "0.1.2",
"authors": [ "authors": [
"Robert von Burg" "Robert von Burg"
], ],

View File

@ -106,14 +106,7 @@
<!-- Observers --> <!-- Observers -->
observeInput: function (newValue, oldValue) { observeInput: function (newValue, oldValue) {
this.debounce("inputDebounce", function () { this.debounce("inputDebounce", function () {
// save the previous value so it may be reset this._setInput(newValue, false);
this.set("prevDebouncedInput", this.debouncedInput);
// set the debounced input after delay
this.set("debouncedInput", newValue);
this.fire('strolch-wc-debounced-input-changed', {
input: newValue,
enterPressed: false
});
}, 500); }, 500);
}, },
@ -124,21 +117,27 @@
// if enter was pressed // if enter was pressed
if (event.keyCode === 13) { if (event.keyCode === 13) {
this.debounce("inputDebounce", function () { this.debounce("inputDebounce", function () {
// save the previous value so it may be reset this._setInput(this.input, true);
this.set("prevDebouncedInput", this.debouncedInput);
// set the debounced input after delay
this.set("debouncedInput", this.input);
this.fire('strolch-wc-debounced-input-changed', {
input: this.input,
enterPressed: true
});
}, 200); }, 200);
} }
}, },
_setInput: function (newValue, enterPressed) {
// save the previous value so it may be reset
this.set("prevDebouncedInput", this.debouncedInput);
// set the debounced input after delay
this.set("debouncedInput", newValue);
this.fire('strolch-wc-debounced-input-changed', {
input: newValue,
enterPressed: enterPressed
});
},
<!-- Functions --> <!-- Functions -->
onClearTapped: function (event) { onClearTapped: function () {
this.setInputTerm(""); this.setInputTerm("");
this.cancelDebouncer("inputDebounce");
this._setInput("", false);
}, },
undoLastInput: function () { undoLastInput: function () {
// apply the last debounced input // apply the last debounced input