Skip to content

Commit

Permalink
add keyboard event key checks
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Jan 21, 2025
1 parent 309658e commit 5c3bd2a
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
*/
package org.dominokit.domino.ui.keyboard;

import static org.dominokit.domino.ui.keyboard.KeyboardKeyListener.ARROWDOWN;
import static org.dominokit.domino.ui.keyboard.KeyboardKeyListener.ARROWLEFT;
import static org.dominokit.domino.ui.keyboard.KeyboardKeyListener.ARROWRIGHT;
import static org.dominokit.domino.ui.keyboard.KeyboardKeyListener.ARROWUP;
import static org.dominokit.domino.ui.keyboard.KeyboardKeyListener.BACKSPACE;
import static org.dominokit.domino.ui.keyboard.KeyboardKeyListener.DELETE;
import static org.dominokit.domino.ui.keyboard.KeyboardKeyListener.ENTER;
import static org.dominokit.domino.ui.keyboard.KeyboardKeyListener.ESCAPE;
import static org.dominokit.domino.ui.keyboard.KeyboardKeyListener.SPACE;
import static org.dominokit.domino.ui.keyboard.KeyboardKeyListener.TAB;

import elemental2.dom.KeyboardEvent;
import elemental2.dom.Node;
import org.dominokit.domino.ui.events.HasDefaultEventOptions;
import org.dominokit.domino.ui.utils.LazyInitializer;
Expand Down Expand Up @@ -85,6 +97,50 @@ public KeyboardEvents(T element) {
new LazyInitializer(() -> element.addEventListener(BEFORE_INPUT, beforeinputListener));
}

public static boolean isEscape(KeyboardEvent event) {
return isKey(ESCAPE, event);
}

public static boolean isBackspace(KeyboardEvent event) {
return isKey(BACKSPACE, event);
}

public static boolean isDelete(KeyboardEvent event) {
return isKey(DELETE, event);
}

public static boolean isArrowDown(KeyboardEvent event) {
return isKey(ARROWDOWN, event);
}

public static boolean isArrowUp(KeyboardEvent event) {
return isKey(ARROWUP, event);
}

public static boolean isArrowRight(KeyboardEvent event) {
return isKey(ARROWRIGHT, event);
}

public static boolean isArrowLeft(KeyboardEvent event) {
return isKey(ARROWLEFT, event);
}

public static boolean isEnter(KeyboardEvent event) {
return isKey(ENTER, event);
}

public static boolean isSpace(KeyboardEvent event) {
return isKey(SPACE, event);
}

public static boolean isTab(KeyboardEvent event) {
return isKey(TAB, event);
}

public static boolean isKey(String key, KeyboardEvent event) {
return event.key.equalsIgnoreCase(key);
}

/**
* Adds a keydown event listener to the element and associates it with the provided {@code
* onKeyDown} consumer.
Expand Down

0 comments on commit 5c3bd2a

Please sign in to comment.