Skip to content

Commit

Permalink
fix #983 Keypress is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Dec 31, 2024
1 parent ffd1a9f commit e18077f
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public SearchTableAction<T> setAutoSearch(boolean autoSearch) {
}

textBox.addEventListener(
EventType.keypress.getName(),
EventType.keydown.getName(),
evt -> {
if (ElementUtil.isEnterKey(Js.uncheckedCast(evt))) {
search();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void initDateBox() {

getInputElement()
.addEventListener(
EventType.keypress.getName(),
EventType.keydown.getName(),
evt -> {
KeyboardEvent keyboardEvent = Js.cast(evt);
if (isEnterKey(keyboardEvent) || isSpaceKey(keyboardEvent)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ public FieldsGrouping onKeyUp(KeyboardEventsHandler handler) {
return this;
}

@Deprecated
public FieldsGrouping onKeyPress(KeyboardEventsHandler handler) {
HTMLElement[] elements = getInputElements();
handler.accept(KeyboardEvents.listenOnKeyPress(elements));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public NumberBox(String label) {
setAutoValidation(true);
enableFormatting();

getInputElement().addEventListener(EventType.keypress, this::onKeyPress);
getInputElement().addEventListener(EventType.keydown, this::onKeyDown);
getInputElement().addEventListener(EventType.paste, this::onPaste);
}

Expand Down Expand Up @@ -114,7 +114,7 @@ protected String createKeyMatch() {
return sB.toString();
}

protected void onKeyPress(Event event) {
protected void onKeyDown(Event event) {
KeyboardEvent keyboardEvent = Js.uncheckedCast(event);
if (!keyboardEvent.key.matches(createKeyMatch())) event.preventDefault();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public ValueBox(String type, String label) {
}

protected void onEnterKey() {
listenOnKeyPress(getInputElement().element())
listenOnKeyDown(getInputElement().element())
.onEnter(
evt -> {
if (DominoUIConfig.INSTANCE.isFocusNextFieldOnEnter()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public class KeyboardEvents<T extends Node> {
public static final String ESCAPE = "escape";
public static final String KEYDOWN = "keydown";
public static final String KEYUP = "keyup";
public static final String KEYPRESS = "keypress";
/**
* @deprecated use keydown instead.
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div">Element: keypress
* event </a>MDN Web Docs (div element)</a>
*/
@Deprecated public static final String KEYPRESS = "keypress";

public static final String ARROWDOWN = "arrowdown";
public static final String ARROWUP = "arrowup";
public static final String ENTER = "enter";
Expand Down Expand Up @@ -113,8 +119,7 @@ public KeyboardEvents(List<T> elements) {
* @param elements the target elements
* @param <T> the type of the element
* @return new instance
* @deprecated use {@link #listenOnKeyDown(Node...)}, {@link #listenOnKeyUp(Node...)}, {@link
* #listenOnKeyPress(Node...)}
* @deprecated use {@link #listenOnKeyDown(Node...)}, {@link #listenOnKeyUp(Node...)}
*/
@Deprecated
public static <T extends Node> KeyboardEvents<T> listenOn(T... elements) {
Expand All @@ -127,8 +132,7 @@ public static <T extends Node> KeyboardEvents<T> listenOn(T... elements) {
* @param elements the target {@link IsElement}
* @param <E> the type of the element
* @return new instance
* @deprecated use {@link #listenOnKeyDown(IsElement...)}, {@link #listenOnKeyUp(IsElement...)},
* {@link #listenOnKeyPress(IsElement...)}
* @deprecated use {@link #listenOnKeyDown(IsElement...)}, {@link #listenOnKeyUp(IsElement...)}
*/
@Deprecated
public static <E extends HTMLElement> KeyboardEvents<E> listenOn(IsElement<E>... elements) {
Expand Down Expand Up @@ -221,7 +225,11 @@ public static <T extends HTMLElement> KeyboardEvents<T> listenOnKeyUp(
* @param elements the target element
* @param <T> the type of the element
* @return new instance
* @deprecated use keydown instead.
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div">Element: keypress
* event </a>MDN Web Docs (div element)</a>
*/
@Deprecated
@SuppressWarnings("unchecked")
public static <T extends Node> KeyboardEvents<T> listenOnKeyPress(T... elements) {
return new KeyboardEvents<>(KEYPRESS, elements);
Expand All @@ -233,7 +241,11 @@ public static <T extends Node> KeyboardEvents<T> listenOnKeyPress(T... elements)
* @param elements the target {@link IsElement}
* @param <T> the type of the element
* @return new instance
* @deprecated use keydown instead.
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div">Element: keypress
* event </a>MDN Web Docs (div element)</a>
*/
@Deprecated
@SuppressWarnings("unchecked")
public static <T extends HTMLElement> KeyboardEvents<T> listenOnKeyPress(
IsElement<T>... elements) {
Expand All @@ -247,7 +259,11 @@ public static <T extends HTMLElement> KeyboardEvents<T> listenOnKeyPress(
* @param elements the target {@link IsElement}
* @param <T> the type of the element
* @return new instance
* @deprecated use keydown instead.
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div">Element: keypress
* event </a>MDN Web Docs (div element)</a>
*/
@Deprecated
@SuppressWarnings("unchecked")
public static <T extends HTMLElement> KeyboardEvents<T> listenOnKeyPress(
List<IsElement<T>> elements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private ModalBackDrop() {
}
})
.addEventListener(
EventType.keypress,
EventType.keydown,
event -> {
if (element.isEqualNode(Js.uncheckedCast(event.target))) {
closeCurrentOpen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void run() {
}

searchInput.addEventListener(
EventType.keypress.getName(),
EventType.keydown.getName(),
evt -> {
if (ElementUtil.isEnterKey(Js.uncheckedCast(evt))) {
searchHandler.onSearch(searchInput.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public SearchBox setAutoSearch(boolean autoSearch) {
}

textBox.addEventListener(
EventType.keypress.getName(),
EventType.keydown.getName(),
evt -> {
if (ElementUtil.isEnterKey(Js.uncheckedCast(evt))) {
doSearch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void run() {
});

inputElement.addEventListener(
EventType.keypress.getName(),
EventType.keydown.getName(),
evt -> {
if (ElementUtil.isEnterKey(Js.uncheckedCast(evt))) {
DelayedTextInput.this.onEnterAction.doAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static boolean isEscapeKey(KeyboardEvent keyboardEvent) {
* will be called only once, if the element is appended more than once a new callback should be
* registered.
*
* @param element the {@link HTMLElement} which is going to be added to the body
* @param element the {@link HTMLElementvirt} which is going to be added to the body
* @param callback {@link ObserverCallback}
* @return an Optional {@link ElementObserver}
*/
Expand Down Expand Up @@ -214,7 +214,7 @@ public static <T extends HasInputElement> T numbersOnly(T hasInputElement) {
hasInputElement
.getInputElement()
.addEventListener(
"keypress",
"keydown",
evt -> {
KeyboardEvent keyboardEvent = Js.uncheckedCast(evt);
if (!(isMinusKey(keyboardEvent.key) || keyboardEvent.key.matches("^\\d+$"))) {
Expand Down Expand Up @@ -247,7 +247,7 @@ public static <T extends HasInputElement> T decimalOnly(T hasInputElement) {
hasInputElement
.getInputElement()
.addEventListener(
"keypress",
"keydown",
evt -> {
KeyboardEvent keyboardEvent = Js.uncheckedCast(evt);
String key = keyboardEvent.key;
Expand Down

0 comments on commit e18077f

Please sign in to comment.