From 77c29731895297aac2501e8535de9fd83595af10 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 20 Feb 2025 18:20:04 +0200 Subject: [PATCH 1/3] Added API to configure the filtering debounce timeout PoC created based on suggestion by @Aleksey2093 Number of different issues related to topic, like #6863 --- .../com/vaadin/flow/component/combobox/ComboBox.java | 12 ++++++++++++ .../META-INF/resources/frontend/comboBoxConnector.js | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java b/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java index 50143345e8a..b40b562b47e 100644 --- a/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java +++ b/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java @@ -450,4 +450,16 @@ public ComboBoxI18n setRequiredErrorMessage(String errorMessage) { return this; } } + + /** + * Sets the "debounce timeout" that the component waits for a short pause in + * typing, before triggering a server-side visit to filter items. The + * default is 500ms. + * + * @param filterTimeout the time in milliseconds that needs to happen + * between keystrokes until filtering is triggered. + */ + public void setFilterTimeout(int filterTimeout) { + + } } diff --git a/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/resources/META-INF/resources/frontend/comboBoxConnector.js b/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/resources/META-INF/resources/frontend/comboBoxConnector.js index 3af8ceaea2b..cb3c726bc1f 100644 --- a/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/resources/META-INF/resources/frontend/comboBoxConnector.js +++ b/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/resources/META-INF/resources/frontend/comboBoxConnector.js @@ -89,7 +89,11 @@ window.Vaadin.Flow.comboBoxConnector.initLazy = (comboBox) => { if (filterChanged) { cache = {}; lastFilter = params.filter; - this._filterDebouncer = Debouncer.debounce(this._filterDebouncer, timeOut.after(500), () => { + let timerValue = 500; + if (comboBox.filterDebouncerTimer) { + timerValue = comboBox.filterDebouncerTimer; + } + this._filterDebouncer = Debouncer.debounce(this._filterDebouncer, timeOut.after(timerValue), () => { if (serverFacade.getLastFilterSentToServer() === params.filter) { // Fixes the case when the filter changes // to something else and back to the original value From 499385ebfbb69e69dfa03700eb99772fbf2ab0d6 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 20 Feb 2025 18:38:15 +0200 Subject: [PATCH 2/3] Eh, method body missing --- .../main/java/com/vaadin/flow/component/combobox/ComboBox.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java b/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java index b40b562b47e..e212b7db754 100644 --- a/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java +++ b/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java @@ -460,6 +460,6 @@ public ComboBoxI18n setRequiredErrorMessage(String errorMessage) { * between keystrokes until filtering is triggered. */ public void setFilterTimeout(int filterTimeout) { - + getElement().setProperty("filterDebouncerTimer", filterTimeout + ""); } } From b137997d8f5436e369fbb8006b917b3b89e35382 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 20 Feb 2025 18:51:01 +0200 Subject: [PATCH 3/3] mvn spotless:apply (had to remove invalid deps vaadin-tabs-flow to make this work) --- .../java/com/vaadin/flow/component/combobox/ComboBox.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java b/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java index e212b7db754..32e896fd66e 100644 --- a/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java +++ b/vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src/main/java/com/vaadin/flow/component/combobox/ComboBox.java @@ -456,8 +456,9 @@ public ComboBoxI18n setRequiredErrorMessage(String errorMessage) { * typing, before triggering a server-side visit to filter items. The * default is 500ms. * - * @param filterTimeout the time in milliseconds that needs to happen - * between keystrokes until filtering is triggered. + * @param filterTimeout + * the time in milliseconds that needs to happen between + * keystrokes until filtering is triggered. */ public void setFilterTimeout(int filterTimeout) { getElement().setProperty("filterDebouncerTimer", filterTimeout + "");