From 3748613f1b2a4bb3d4bd90bb363a395a64f1a1d1 Mon Sep 17 00:00:00 2001 From: "Ahmad K. Bawaneh" Date: Mon, 30 Oct 2023 11:28:03 +0300 Subject: [PATCH] fix #867 Moving focus from Select element --- .../domino/ui/config/FormsFieldsConfig.java | 13 +++++++++++++ .../domino/ui/forms/suggest/AbstractSelect.java | 12 +++++++++++- .../dominokit/domino/ui/forms/suggest/Select.java | 3 ++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/config/FormsFieldsConfig.java b/domino-ui/src/main/java/org/dominokit/domino/ui/config/FormsFieldsConfig.java index 2fd58e449..e1972bc1e 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/config/FormsFieldsConfig.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/config/FormsFieldsConfig.java @@ -109,6 +109,19 @@ default NumberParsers getNumberParsers() { return new NumberParsers() {}; } + /** + * Use this method to configure if pressing tab while select field is focused will move the focus + * to the select arrow addon or not. + * + *

Defaults to : false + * + * @return a boolean, true to enable focus on select arrow by pressing tab, false + * disable focus on select arrow when pressing tab. + */ + default boolean isTabFocusSelectArrowEnabled() { + return false; + } + /** * Use this method to define the default position of the field label, top or left * 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 42ca3c423..4af1abf1f 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 @@ -129,11 +129,21 @@ public AbstractSelect() { Icons.chevron_down() .addCss(dui_form_select_drop_arrow) .clickable() + .setAttribute("tabindex", getConfig().isTabFocusSelectArrowEnabled() ? "0" : "-1") + .setAttribute( + "aria-expanded", getConfig().isTabFocusSelectArrowEnabled() ? "true" : "false") .addClickListener( evt -> { evt.stopPropagation(); openOptionMenu(); - }))); + }) + .onKeyPress( + keyEvents -> + keyEvents.onEnter( + evt -> { + evt.stopPropagation(); + openOptionMenu(); + })))); appendChild( PrimaryAddOn.of( diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/Select.java b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/Select.java index 5ff5a3137..3c8e2f0c2 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/Select.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/forms/suggest/Select.java @@ -15,6 +15,7 @@ */ package org.dominokit.domino.ui.forms.suggest; +import static java.util.Objects.isNull; import static java.util.Objects.nonNull; import java.util.Objects; @@ -105,7 +106,7 @@ protected void onOptionSelected(SelectOption option, boolean silent) { @Override public Select withOption(SelectOption option, boolean silent) { V oldValue = getValue(); - if (!Objects.equals(option.getValue(), oldValue)) { + if (!Objects.equals(option.getValue(), oldValue) || isNull(oldValue)) { doSetOption(option); updateTextValue();