From f0637f9d252a2437a713fe15a7432f57584a57a4 Mon Sep 17 00:00:00 2001 From: "Ahmad K. Bawaneh" Date: Mon, 2 Dec 2024 16:31:09 +0300 Subject: [PATCH] fix #983 Keypress is deprecated --- .../dominokit/domino/ui/events/EventType.java | 10 ++- .../dominokit/domino/ui/forms/DateBox.java | 2 +- .../domino/ui/forms/DateRangeBox.java | 2 +- .../domino/ui/forms/FieldsGrouping.java | 4 ++ .../ui/forms/InputFieldInitializer.java | 2 +- .../dominokit/domino/ui/forms/NumberBox.java | 5 +- .../dominokit/domino/ui/forms/TimeBox.java | 2 +- .../ui/forms/suggest/AbstractSelect.java | 6 +- .../domino/ui/keyboard/HasKeyboardEvents.java | 23 +++++++ .../domino/ui/keyboard/KeyboardEvents.java | 63 ++++++++++++++++--- .../org/dominokit/domino/ui/menu/Menu.java | 13 +++- .../dominokit/domino/ui/search/SearchBox.java | 2 +- .../domino/ui/utils/BaseDominoElement.java | 61 +++++++++++++----- .../domino/ui/utils/HasCollapseListeners.java | 12 ++-- .../ui/utils/HasOpenCloseListeners.java | 10 +-- .../domino/ui/utils/KeyboardNavigation.java | 38 ++++++++--- .../dui-components/domino-ui-colors-dark.css | 1 + .../dui-components/domino-ui-colors-light.css | 1 + 18 files changed, 196 insertions(+), 61 deletions(-) diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/events/EventType.java b/domino-ui/src/main/java/org/dominokit/domino/ui/events/EventType.java index 3ebf5abf2..92fc2672b 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/events/EventType.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/events/EventType.java @@ -97,8 +97,14 @@ public interface EventType { /** Represents the "keydown" event type. */ EventType keydown = () -> "keydown"; - /** Represents the "keypress" event type. */ - EventType keypress = () -> "keypress"; + /** + * Represents the "keypress" event type. + * + * @deprecated use keydown instead. + * @see Element: keypress + * event MDN Web Docs (div element) + */ + @Deprecated EventType keypress = () -> "keypress"; /** Represents the "keyup" event type. */ EventType keyup = () -> "keyup"; diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/DateBox.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/DateBox.java index 6082fb78a..f25806bf4 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/DateBox.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/DateBox.java @@ -157,7 +157,7 @@ public DateBox( onDetached(mutationRecord -> popover.close()); getInputElement() - .onKeyPress(keyEvents -> keyEvents.onEnter(evt -> doOpen()).onSpace(evt -> doOpen())); + .onKeyDown(keyEvents -> keyEvents.onEnter(evt -> doOpen()).onSpace(evt -> doOpen())); addValidator( component -> { try { diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/DateRangeBox.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/DateRangeBox.java index b65ce02ae..0ed61821d 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/DateRangeBox.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/DateRangeBox.java @@ -178,7 +178,7 @@ public DateRangeBox( onDetached(mutationRecord -> popover.close()); getInputElement() - .onKeyPress(keyEvents -> keyEvents.onEnter(evt -> doOpen()).onSpace(evt -> doOpen())); + .onKeyDown(keyEvents -> keyEvents.onEnter(evt -> doOpen()).onSpace(evt -> doOpen())); addValidator( component -> { try { diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/FieldsGrouping.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/FieldsGrouping.java index 6fa567cc4..cc43ec175 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/FieldsGrouping.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/FieldsGrouping.java @@ -551,7 +551,11 @@ public FieldsGrouping onKeyUp(KeyEventsConsumer handler) { * * @param handler The event handler to execute on key press events. * @return The current `FieldsGrouping` instance for method chaining. + * @deprecated use keydown instead. + * @see Element: keypress + * event MDN Web Docs (div element) */ + @Deprecated public FieldsGrouping onKeyPress(KeyEventsConsumer handler) { HTMLElement[] elements = getInputElements(); Arrays.stream(elements) diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/InputFieldInitializer.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/InputFieldInitializer.java index 055a3f513..1cc5c5f09 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/InputFieldInitializer.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/InputFieldInitializer.java @@ -105,7 +105,7 @@ public InputFieldInitializer init(HasInputElement hasInput) { countableElement.updateCounter( hasLength.getLength(), countableElement.getMaxCount())); } - inputElement.onKeyPress( + inputElement.onKeyDown( keyEvents -> { keyEvents.onEnter( evt -> { diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/NumberBox.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/NumberBox.java index 8acb8dac6..b80cf2ca2 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/NumberBox.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/NumberBox.java @@ -17,7 +17,6 @@ import static java.util.Objects.isNull; import static java.util.Objects.nonNull; -import static org.dominokit.domino.ui.utils.Domino.*; import static org.dominokit.domino.ui.utils.Domino.div; import static org.dominokit.domino.ui.utils.Domino.input; @@ -89,7 +88,7 @@ public NumberBox() { setAutoValidation(true); enableFormatting(); - getInputElement().addEventListener(EventType.keypress, this::onKeyPress); + getInputElement().addEventListener(EventType.keydown, this::onKeyDown); getInputElement().addEventListener(EventType.paste, this::onPaste); } @@ -210,7 +209,7 @@ protected String createKeyMatch() { * * @param event The keyboard event associated with the key press. */ - protected void onKeyPress(Event event) { + protected void onKeyDown(Event event) { KeyboardEvent keyboardEvent = Js.uncheckedCast(event); if (!keyboardEvent.key.matches(createKeyMatch())) event.preventDefault(); } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/TimeBox.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/TimeBox.java index c777a360b..5e18ce644 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/TimeBox.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/TimeBox.java @@ -131,7 +131,7 @@ public TimeBox(Date date, DateTimeFormatInfo dateTimeFormatInfo) { onDetached(mutationRecord -> popover.close()); getInputElement() - .onKeyPress(keyEvents -> keyEvents.onEnter(evt -> doOpen()).onSpace(evt -> doOpen())); + .onKeyDown(keyEvents -> keyEvents.onEnter(evt -> doOpen()).onSpace(evt -> doOpen())); addValidator( component -> { try { diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSelect.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSelect.java index 3ba797d51..76294865e 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSelect.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/AbstractSelect.java @@ -103,7 +103,7 @@ public AbstractSelect() { .addEventListener("input", evt -> onTypingStart()) .addCss(dui_auto_type_input, dui_hidden) .setTabIndex(-1) - .onKeyPress(keyEvents -> keyEvents.alphanumeric(Event::stopPropagation))); + .onKeyDown(keyEvents -> keyEvents.alphanumeric(Event::stopPropagation))); DelayedTextInput.create(typingElement, getTypeAheadDelay()) .setDelayedAction( @@ -126,7 +126,7 @@ public AbstractSelect() { DomGlobal.setTimeout(p0 -> optionsMenu.focusFirstMatch(token), 0); }); - onKeyPress( + onKeyDown( keyEvents -> { keyEvents.alphanumeric( evt -> { @@ -192,7 +192,7 @@ public AbstractSelect() { evt.stopPropagation(); openOptionMenu(); }) - .onKeyPress( + .onKeyDown( keyEvents -> keyEvents.onEnter( evt -> { diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/keyboard/HasKeyboardEvents.java b/domino-ui/src/main/java/org/dominokit/domino/ui/keyboard/HasKeyboardEvents.java index 8a6ab46f9..47d931558 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/keyboard/HasKeyboardEvents.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/keyboard/HasKeyboardEvents.java @@ -58,14 +58,22 @@ public interface HasKeyboardEvents { * * @param onKeyPress The {@link KeyEventsConsumer} to call when a key is pressed and held down. * @return The instance of type {@code T} for method chaining. + * @deprecated use keydown instead. + * @see Element: keypress + * event MDN Web Docs (div element) */ + @Deprecated T onKeyPress(KeyEventsConsumer onKeyPress); /** * Stops listening for key press and hold events. * * @return The instance of type {@code T} for method chaining. + * @deprecated use keydown instead. + * @see Element: keypress + * event MDN Web Docs (div element) */ + @Deprecated T stopOnKeyPress(); /** @@ -83,6 +91,21 @@ public interface HasKeyboardEvents { */ T stopOnInput(); + /** + * Registers an event listener to be called when an beforeinput is applied. + * + * @param onBeforeInput The {@link KeyEventsConsumer} to call when an beforeinput is applied. + * @return The instance of type {@code T} for method chaining. + */ + T onBeforeInput(KeyEventsConsumer onBeforeInput); + + /** + * Stops listening for beforeinput events. + * + * @return The instance of type {@code T} for method chaining. + */ + T stopOnBeforeInput(); + /** * Gets the keyboard event options associated with this instance. * diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/keyboard/KeyboardEvents.java b/domino-ui/src/main/java/org/dominokit/domino/ui/keyboard/KeyboardEvents.java index 44cb8c66d..a38b5d2fa 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/keyboard/KeyboardEvents.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/keyboard/KeyboardEvents.java @@ -39,10 +39,17 @@ public class KeyboardEvents /** The constant representing the "keyup" event type. */ public static final String KEYUP = "keyup"; - /** The constant representing the "keypress" event type. */ - public static final String KEYPRESS = "keypress"; + /** + * The constant representing the "keypress" event type. + * + * @deprecated use keydown instead. + * @see Element: keypress + * event MDN Web Docs (div element) + */ + @Deprecated public static final String KEYPRESS = "keypress"; public static final String INPUT = "input"; + public static final String BEFORE_INPUT = "beforeinput"; private KeyboardEventOptions defaultOptions = KeyboardEventOptions.create(); private final T element; @@ -51,11 +58,13 @@ public class KeyboardEvents private KeyboardKeyListener keyDownListener = new KeyboardKeyListener(this); private KeyboardKeyListener keyPressListener = new KeyboardKeyListener(this); private KeyboardKeyListener inputListener = new KeyboardKeyListener(this); + private KeyboardKeyListener beforeinputListener = new KeyboardKeyListener(this); private LazyInitializer keyUpListenerInitializer; private LazyInitializer keyDownListenerInitializer; private LazyInitializer keyPressListenerInitializer; - private LazyInitializer InputListenerInitializer; + private LazyInitializer inputListenerInitializer; + private LazyInitializer beforeInputListenerInitializer; /** * Creates a new instance of {@code KeyboardEvents} for the specified DOM element. @@ -70,8 +79,10 @@ public KeyboardEvents(T element) { new LazyInitializer(() -> element.addEventListener(KEYDOWN, keyDownListener)); keyPressListenerInitializer = new LazyInitializer(() -> element.addEventListener(KEYPRESS, keyPressListener)); - InputListenerInitializer = + inputListenerInitializer = new LazyInitializer(() -> element.addEventListener(INPUT, inputListener)); + beforeInputListenerInitializer = + new LazyInitializer(() -> element.addEventListener(BEFORE_INPUT, beforeinputListener)); } /** @@ -128,7 +139,11 @@ public KeyboardEvents stopListenOnKeyUp() { * * @param onKeyPress The consumer that will receive keypress events. * @return This {@code KeyboardEvents} instance for method chaining. + * @deprecated use listenOnKeyDown instead. + * @see Element: keypress + * event MDN Web Docs (div element) */ + @Deprecated public KeyboardEvents listenOnKeyPress(KeyEventsConsumer onKeyPress) { keyPressListenerInitializer.apply(); onKeyPress.accept(keyPressListener); @@ -139,7 +154,11 @@ public KeyboardEvents listenOnKeyPress(KeyEventsConsumer onKeyPress) { * Removes the keypress event listener from the element. * * @return This {@code KeyboardEvents} instance for method chaining. + * @deprecated use listenOnKeyDown instead. + * @see Element: keypress + * event MDN Web Docs (div element) */ + @Deprecated public KeyboardEvents stopListenOnKeyPress() { element.removeEventListener(KEYPRESS, keyPressListener); keyPressListenerInitializer.reset(); @@ -147,26 +166,50 @@ public KeyboardEvents stopListenOnKeyPress() { } /** - * Adds a keypress event listener to the element and associates it with the provided {@code - * onInput} consumer. + * Adds a input event listener to the element and associates it with the provided {@code onInput} + * consumer. * - * @param onInput The consumer that will receive keypress events. + * @param onInput The consumer that will receive input events. * @return This {@code KeyboardEvents} instance for method chaining. */ public KeyboardEvents listenOnInput(KeyEventsConsumer onInput) { - InputListenerInitializer.apply(); + inputListenerInitializer.apply(); onInput.accept(inputListener); return this; } /** - * Removes the keypress event listener from the element. + * Adds a keypress event listener to the element and associates it with the provided {@code + * onBeforeInput} consumer. + * + * @param onBeforeInput The consumer that will receive beforeinput events. + * @return This {@code KeyboardEvents} instance for method chaining. + */ + public KeyboardEvents listenOnBeforeInput(KeyEventsConsumer onBeforeInput) { + beforeInputListenerInitializer.apply(); + onBeforeInput.accept(beforeinputListener); + return this; + } + + /** + * Removes the input event listener from the element. * * @return This {@code KeyboardEvents} instance for method chaining. */ public KeyboardEvents stopListenOnInput() { element.removeEventListener(INPUT, inputListener); - InputListenerInitializer.reset(); + inputListenerInitializer.reset(); + return this; + } + + /** + * Removes the beforeinput event listener from the element. + * + * @return This {@code KeyboardEvents} instance for method chaining. + */ + public KeyboardEvents stopListenOnBeforeInput() { + element.removeEventListener(BEFORE_INPUT, beforeinputListener); + beforeInputListenerInitializer.reset(); return this; } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/menu/Menu.java b/domino-ui/src/main/java/org/dominokit/domino/ui/menu/Menu.java index 42ff0e0f0..d23b7024d 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/menu/Menu.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/menu/Menu.java @@ -185,7 +185,7 @@ public Menu() { onAddMissingElement(); }; - addClickListener(evt -> evt.stopPropagation()); + addClickListener(Event::stopPropagation); onKeyDown( keyEvents -> { @@ -1405,16 +1405,23 @@ private void doOpen(boolean focus) { searchBox.get().clearSearch(); } triggerOpenListeners(this); + boolean shouldFocus = focus; onAttached( mutationRecord -> { position(); - if (focus) { + if (shouldFocus) { focus(); } elementOf(getMenuAppendTarget()).onDetached(targetDetach -> close()); }); appendStrategy.onAppend(getMenuAppendTarget(), element.element()); - onDetached(record -> close()); + onDetached( + record -> { + close(); + if (isDropDown()) { + triggerCloseListeners(this); + } + }); if (smallScreen && nonNull(parent) && parent.isDropDown()) { parent.collapse(); menuHeader.get().insertFirst(backArrowContainer); diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/search/SearchBox.java b/domino-ui/src/main/java/org/dominokit/domino/ui/search/SearchBox.java index 9c91863a5..2ff31808a 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/search/SearchBox.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/search/SearchBox.java @@ -213,7 +213,7 @@ public SearchBox setAutoSearch(boolean autoSearch) { autoSearchTimer.cancel(); } - textBox.onKeyPress(keyEvents -> keyEvents.onEnter(evt -> doSearch())); + textBox.onKeyDown(keyEvents -> keyEvents.onEnter(evt -> doSearch())); return this; } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BaseDominoElement.java b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BaseDominoElement.java index da65cca23..e34475f95 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BaseDominoElement.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/BaseDominoElement.java @@ -168,7 +168,7 @@ public abstract class BaseDominoElement> closeListeners; @@ -518,8 +518,8 @@ public T setCollapseStrategy(CollapseStrategy strategy) { * @return The modified DOM element. */ @Override - public T pauseCloseListeners() { - this.closeListenersPaused = true; + public T pauseOpenCloseListeners() { + this.openCloseListenersPaused = true; return (T) this; } @@ -529,8 +529,8 @@ public T pauseCloseListeners() { * @return The modified DOM element. */ @Override - public T resumeCloseListeners() { - this.closeListenersPaused = false; + public T resumeOpenCloseListeners() { + this.openCloseListenersPaused = false; return (T) this; } @@ -542,7 +542,7 @@ public T resumeCloseListeners() { */ @Override public T togglePauseCloseListeners(boolean toggle) { - this.closeListenersPaused = toggle; + this.openCloseListenersPaused = toggle; return (T) this; } @@ -586,8 +586,8 @@ private Set> openListeners() { * @return {@code true} if close listeners are paused, {@code false} otherwise. */ @Override - public boolean isCloseListenersPaused() { - return this.closeListenersPaused; + public boolean isOpenCloseListenersPaused() { + return this.openCloseListenersPaused; } /** @@ -598,7 +598,7 @@ public boolean isCloseListenersPaused() { */ @Override public T triggerCloseListeners(T component) { - if (!this.closeListenersPaused) { + if (!this.openCloseListenersPaused) { getCloseListeners().forEach(closeListener -> closeListener.onClosed((T) this)); } return (T) this; @@ -612,7 +612,7 @@ public T triggerCloseListeners(T component) { */ @Override public T triggerOpenListeners(T component) { - if (!this.closeListenersPaused) { + if (!this.openCloseListenersPaused) { getOpenListeners().forEach(openListener -> openListener.onOpened((T) this)); } return (T) this; @@ -2019,7 +2019,7 @@ public T removeOnBeforeRemoveListener(Consumer handler) { */ public T addOnRemoveListener(Consumer handler) { if (nonNull(handler)) { - this.onRemoveHandlers.add(handler); + this.onRemoveHandlers().add(handler); } return (T) this; } @@ -2032,7 +2032,7 @@ public T addOnRemoveListener(Consumer handler) { */ public T removeOnRemoveListener(Consumer handler) { if (nonNull(handler)) { - this.onRemoveHandlers.remove(handler); + this.onRemoveHandlers().remove(handler); } return (T) this; } @@ -4246,7 +4246,11 @@ public T stopOnKeyUp() { * * @param onKeyPress The event handler for key press events. * @return The modified DOM element. + * @deprecated use keydown instead. + * @see Element: keypress + * event MDN Web Docs (div element) */ + @Deprecated @Override public T onKeyPress(KeyEventsConsumer onKeyPress) { keyEventsInitializer.apply(); @@ -4258,7 +4262,11 @@ public T onKeyPress(KeyEventsConsumer onKeyPress) { * Stops listening to key press events. * * @return The modified DOM element. + * @deprecated use keydown instead. + * @see Element: keypress + * event MDN Web Docs (div element) */ + @Deprecated @Override public T stopOnKeyPress() { keyEventsInitializer.apply(); @@ -4267,9 +4275,9 @@ public T stopOnKeyPress() { } /** - * Registers an event handler to be executed when a key is pressed and released. + * Registers an event handler to be executed when input. * - * @param onInput The event handler for key press events. + * @param onInput The event handler for input events. * @return The modified DOM element. */ @Override @@ -4291,6 +4299,31 @@ public T stopOnInput() { return (T) this; } + /** + * Registers an event handler to be executed before input. + * + * @param onBeforeInput The event handler for before input events. + * @return The modified DOM element. + */ + @Override + public T onBeforeInput(KeyEventsConsumer onBeforeInput) { + keyEventsInitializer.apply(); + keyboardEvents.listenOnBeforeInput(onBeforeInput); + return (T) this; + } + + /** + * Stops listening to beforeinput events. + * + * @return The modified DOM element. + */ + @Override + public T stopOnBeforeInput() { + keyEventsInitializer.apply(); + keyboardEvents.stopListenOnBeforeInput(); + return (T) this; + } + /** * Retrieves the options for keyboard events. * diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasCollapseListeners.java b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasCollapseListeners.java index 28b3c2a01..199ec30ad 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasCollapseListeners.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasCollapseListeners.java @@ -106,22 +106,22 @@ default boolean hasExpandListener(ExpandListener expandListener) { * Pauses all collapse event listeners associated with the element. * * @return The element with its collapse event listeners paused. - * @deprecated use {@link #pauseCloseListeners} + * @deprecated use {@link #pauseOpenCloseListeners} */ @Deprecated default T pauseCollapseListeners() { - return pauseCloseListeners(); + return pauseOpenCloseListeners(); } /** * Resumes all pause collapse event listeners associated with the element. * * @return The element with its collapse event listeners resumed. - * @deprecated use {@link #resumeCloseListeners} + * @deprecated use {@link #resumeOpenCloseListeners} */ @Deprecated default T resumeCollapseListeners() { - return resumeCloseListeners(); + return resumeOpenCloseListeners(); } /** @@ -195,11 +195,11 @@ default Set> getExpandListeners() { * Checks if the collapse event listeners are currently paused. * * @return {@code true} if the collapse event listeners are paused, {@code false} otherwise. - * @deprecated use {@link #isCloseListenersPaused} + * @deprecated use {@link #isOpenCloseListenersPaused} */ @Deprecated default boolean isCollapseListenersPaused() { - return isCloseListenersPaused(); + return isOpenCloseListenersPaused(); } /** diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasOpenCloseListeners.java b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasOpenCloseListeners.java index cfecb3248..d734d69ab 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasOpenCloseListeners.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasOpenCloseListeners.java @@ -97,14 +97,14 @@ default boolean hasOpenListener(OpenListener openListener) { * * @return The element with its close event listeners paused. */ - T pauseCloseListeners(); + T pauseOpenCloseListeners(); /** * Resumes all pause close event listeners associated with the element. * * @return The element with its close event listeners resumed. */ - T resumeCloseListeners(); + T resumeOpenCloseListeners(); /** * Toggles the pause state of close event listeners associated with the element. @@ -126,7 +126,7 @@ default boolean hasOpenListener(OpenListener openListener) { * afterward. */ default T withPauseCloseListenersToggle(boolean toggle, Handler handler) { - boolean oldState = isCloseListenersPaused(); + boolean oldState = isOpenCloseListenersPaused(); togglePauseCloseListeners(toggle); try { handler.apply((T) this); @@ -147,7 +147,7 @@ default T withPauseCloseListenersToggle(boolean toggle, Handler handler) { * afterward. */ default T withPauseCloseListenersToggle(boolean toggle, AsyncHandler handler) { - boolean oldState = isCloseListenersPaused(); + boolean oldState = isOpenCloseListenersPaused(); togglePauseCloseListeners(toggle); try { handler.apply((T) this, () -> togglePauseCloseListeners(oldState)); @@ -177,7 +177,7 @@ default T withPauseCloseListenersToggle(boolean toggle, AsyncHandler handler) * * @return {@code true} if the close event listeners are paused, {@code false} otherwise. */ - boolean isCloseListenersPaused(); + boolean isOpenCloseListenersPaused(); /** * Triggers all close event listeners associated with the element. diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/KeyboardNavigation.java b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/KeyboardNavigation.java index a6744ccc9..5c6f74550 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/utils/KeyboardNavigation.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/utils/KeyboardNavigation.java @@ -26,6 +26,7 @@ import static org.dominokit.domino.ui.utils.ElementUtil.isSpaceKey; import static org.dominokit.domino.ui.utils.ElementUtil.isTabKey; +import elemental2.dom.Element; import elemental2.dom.Event; import elemental2.dom.EventListener; import elemental2.dom.HTMLElement; @@ -63,6 +64,7 @@ public class KeyboardNavigation> implements EventListener private Consumer> onEndReached = (navigation) -> focusTopFocusableItem(); private Consumer> onStartReached = (navigation) -> focusBottomFocusableItem(); + private Element exitElement; /** * Creates a new `KeyboardNavigation` instance for the given list of items. @@ -308,10 +310,14 @@ private boolean shouldFocus(V itemToFocus) { /** Focuses on the first focusable item in the list. */ public void focusTopFocusableItem() { - for (V item : items) { - if (shouldFocus(item)) { - doFocus(item); - break; + if (nonNull(this.exitElement)) { + this.exitElement.focus(); + } else { + for (V item : items) { + if (shouldFocus(item)) { + doFocus(item); + break; + } } } } @@ -332,11 +338,15 @@ public Optional getTopFocusableItem() { /** Focuses on the last focusable item in the list. */ public void focusBottomFocusableItem() { - for (int i = items.size() - 1; i >= 0; i--) { - V itemToFocus = items.get(i); - if (shouldFocus(itemToFocus)) { - doFocus(itemToFocus); - break; + if (nonNull(this.exitElement)) { + this.exitElement.focus(); + } else { + for (int i = items.size() - 1; i >= 0; i--) { + V itemToFocus = items.get(i); + if (shouldFocus(itemToFocus)) { + doFocus(itemToFocus); + break; + } } } } @@ -397,7 +407,7 @@ private void doEvent(Event event, EventOptions options, EventExecutor executor) */ public KeyboardNavigation registerNavigationHandler( String keyCode, ItemNavigationHandler navigationHandler) { - if (!navigationHandlers.containsKey(keyCode)) { + if (!navigationHandlers.containsKey(keyCode.toLowerCase())) { navigationHandlers.put(keyCode.toLowerCase(), new ArrayList<>()); } navigationHandlers.get(keyCode.toLowerCase()).add(navigationHandler); @@ -443,6 +453,14 @@ public KeyboardNavigation setOnStartReached(Consumer> o return this; } + public Element getExitElement() { + return exitElement; + } + + public void setExitElement(Element exitElement) { + this.exitElement = exitElement; + } + /** * A functional interface for handling focus on items. * diff --git a/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-dark.css b/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-dark.css index 8010d8fdc..5166492c2 100644 --- a/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-dark.css +++ b/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-dark.css @@ -8,6 +8,7 @@ --dui-color-alternate: var(--dui-color-5); /*--dui-text-color: var(--dui-color-dark);*/ --dui-highlight-color: var(--dui-clr-black); + --dui-color-invert : var(--dui-clr-black); color: var(--dui-color); diff --git a/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-light.css b/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-light.css index 2ef8c3bc5..b71a2b8fd 100644 --- a/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-light.css +++ b/domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-colors-light.css @@ -8,6 +8,7 @@ --dui-color-alternate: var(--dui-color); /*--dui-text-color: var(--dui-color-dark);*/ --dui-highlight-color: var(--dui-clr-white); + --dui-color-invert : var(--dui-clr-white); color: var(--dui-color); /* ====================== Colors ========================= */