Skip to content

Commit

Permalink
fix #952 add TextArea support to DelayedTextInput
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Aug 8, 2024
1 parent 0b193bd commit 1c0e08a
Showing 1 changed file with 112 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
Expand All @@ -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, () -> {});
}

/**
Expand All @@ -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;
Expand Down

0 comments on commit 1c0e08a

Please sign in to comment.