From 1c0e08a1ecb98c379e7acc89c111a1e18b611c09 Mon Sep 17 00:00:00 2001 From: "Ahmad K. Bawaneh" Date: Thu, 8 Aug 2024 14:31:22 +0300 Subject: [PATCH] fix #952 add TextArea support to DelayedTextInput --- .../domino/ui/utils/DelayedTextInput.java | 116 +++++++++++++++++- 1 file changed, 112 insertions(+), 4 deletions(-) diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/DelayedTextInput.java b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/DelayedTextInput.java index 0bfade70f..2e8f7850b 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/DelayedTextInput.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/DelayedTextInput.java @@ -17,9 +17,12 @@ import static java.util.Objects.isNull; +import elemental2.dom.HTMLElement; import elemental2.dom.HTMLInputElement; +import elemental2.dom.HTMLTextAreaElement; import jsinterop.base.Js; import org.dominokit.domino.ui.elements.InputElement; +import org.dominokit.domino.ui.elements.TextAreaElement; import org.dominokit.domino.ui.events.EventType; import org.gwtproject.timer.client.Timer; @@ -41,7 +44,7 @@ public class DelayedTextInput { private int delay; - private final HTMLInputElement inputElement; + private final HTMLElement inputElement; private Timer autoActionTimer; private DelayedAction delayedAction = () -> {}; private DelayedAction onEnterAction = () -> delayedAction.doAction(); @@ -60,6 +63,20 @@ public static DelayedTextInput create( return new DelayedTextInput(inputElement, delay, delayedAction); } + /** + * Creates a {@code DelayedTextInput} instance for the given HTML input element with a specified + * delay and an action to execute on text input changes. + * + * @param inputElement The HTML input element to monitor for text input changes. + * @param delay The delay in milliseconds before triggering the action. + * @param delayedAction The action to execute when text input changes after the specified delay. + * @return A {@code DelayedTextInput} instance. + */ + public static DelayedTextInput create( + HTMLTextAreaElement inputElement, int delay, DelayedAction delayedAction) { + return new DelayedTextInput(inputElement, delay, delayedAction); + } + /** * Creates a {@code DelayedTextInput} instance for the given HTML input element with a default * delay and an action to execute on text input changes. @@ -76,6 +93,22 @@ public static DelayedTextInput create( delayedAction); } + /** + * Creates a {@code DelayedTextInput} instance for the given HTML input element with a default + * delay and an action to execute on text input changes. + * + * @param inputElement The HTML input element to monitor for text input changes. + * @param delayedAction The action to execute when text input changes after the specified delay. + * @return A {@code DelayedTextInput} instance. + */ + public static DelayedTextInput create( + HTMLTextAreaElement inputElement, DelayedAction delayedAction) { + return new DelayedTextInput( + inputElement, + DominoUIConfig.CONFIG.getUIConfig().getDelayedExecutionDefaultDelay(), + delayedAction); + } + /** * Creates a {@code DelayedTextInput} instance for the given HTML input element with a specified * delay. @@ -88,6 +121,18 @@ public static DelayedTextInput create(HTMLInputElement inputElement, int delay) return new DelayedTextInput(inputElement, delay); } + /** + * Creates a {@code DelayedTextInput} instance for the given HTML input element with a specified + * delay. + * + * @param inputElement The HTML input element to monitor for text input changes. + * @param delay The delay in milliseconds before triggering the action. + * @return A {@code DelayedTextInput} instance. + */ + public static DelayedTextInput create(HTMLTextAreaElement inputElement, int delay) { + return new DelayedTextInput(inputElement, delay); + } + /** * Creates a {@code DelayedTextInput} instance for the given HTML input element with a default * delay. @@ -100,6 +145,18 @@ public static DelayedTextInput create(HTMLInputElement inputElement) { inputElement, DominoUIConfig.CONFIG.getUIConfig().getDelayedExecutionDefaultDelay()); } + /** + * Creates a {@code DelayedTextInput} instance for the given HTML input element with a default + * delay. + * + * @param inputElement The HTML input element to monitor for text input changes. + * @return A {@code DelayedTextInput} instance. + */ + public static DelayedTextInput create(HTMLTextAreaElement inputElement) { + return new DelayedTextInput( + inputElement, DominoUIConfig.CONFIG.getUIConfig().getDelayedExecutionDefaultDelay()); + } + /** * Creates a {@code DelayedTextInput} instance for the given DominoElement with a specified delay. * @@ -137,6 +194,18 @@ public static DelayedTextInput create(InputElement inputElement, int delay) { return create(inputElement.element(), delay); } + /** + * Creates a {@code DelayedTextInput} instance for the given InputElement with a specified delay. + * + * @param inputElement The DominoElement wrapping the HTML input element to monitor for text input + * changes. + * @param delay The delay in milliseconds before triggering the action. + * @return A {@code DelayedTextInput} instance. + */ + public static DelayedTextInput create(TextAreaElement inputElement, int delay) { + return create(inputElement.element(), delay); + } + /** * Creates a {@code DelayedTextInput} instance for the given InputElement with a default delay. * @@ -150,6 +219,19 @@ public static DelayedTextInput create(InputElement inputElement) { DominoUIConfig.CONFIG.getUIConfig().getDelayedExecutionDefaultDelay()); } + /** + * Creates a {@code DelayedTextInput} instance for the given InputElement with a default delay. + * + * @param inputElement The DominoElement wrapping the HTML input element to monitor for text input + * changes. + * @return A {@code DelayedTextInput} instance. + */ + public static DelayedTextInput create(TextAreaElement inputElement) { + return create( + inputElement.element(), + DominoUIConfig.CONFIG.getUIConfig().getDelayedExecutionDefaultDelay()); + } + /** * Constructs a {@code DelayedTextInput} instance for the given HTML input element with a * specified delay. @@ -158,9 +240,18 @@ public static DelayedTextInput create(InputElement inputElement) { * @param delay The delay in milliseconds before triggering the action. */ public DelayedTextInput(HTMLInputElement inputElement, int delay) { - this.inputElement = inputElement; - this.delay = delay; - prepare(); + this((HTMLElement) inputElement, delay, () -> {}); + } + + /** + * Constructs a {@code DelayedTextInput} instance for the given HTML input element with a + * specified delay. + * + * @param inputElement The HTML input element to monitor for text input changes. + * @param delay The delay in milliseconds before triggering the action. + */ + public DelayedTextInput(HTMLTextAreaElement inputElement, int delay) { + this((HTMLElement) inputElement, delay, () -> {}); } /** @@ -172,6 +263,23 @@ public DelayedTextInput(HTMLInputElement inputElement, int delay) { * @param delayedAction The action to execute when text input changes after the specified delay. */ public DelayedTextInput(HTMLInputElement inputElement, int delay, DelayedAction delayedAction) { + this((HTMLElement) inputElement, delay, delayedAction); + } + + /** + * Constructs a {@code DelayedTextInput} instance for the given HTML input element with a + * specified delay and an action to execute on text input changes. + * + * @param inputElement The HTML input element to monitor for text input changes. + * @param delay The delay in milliseconds before triggering the action. + * @param delayedAction The action to execute when text input changes after the specified delay. + */ + public DelayedTextInput( + HTMLTextAreaElement inputElement, int delay, DelayedAction delayedAction) { + this((HTMLElement) inputElement, delay, delayedAction); + } + + private DelayedTextInput(HTMLElement inputElement, int delay, DelayedAction delayedAction) { this.inputElement = inputElement; this.delay = delay; this.delayedAction = delayedAction;