You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2024/12/02 20:12:41 UTC
(wicket) branch wicket-9.x updated (e7d049b6df -> d0c8035fd2)
This is an automated email from the ASF dual-hosted git repository.
adelbene pushed a change to branch wicket-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
from e7d049b6df Fix tab glitch when tabing from and to an autocomplete field, which resulted in a dropdown that didn't open on first character when returning to the field (#1039)
new c05d4b8f70 Added ability to prevent autocomplete to move focus to the next component when selecting an item using the tab key in the autocomplete list
new d227133b22 Fix jshint issues
new fc290a0aff Change the solution to use an enum to make the code clearer and make it easier to add more behaviours later
new d0c8035fd2 Renamed the TabBehavior to KeyTabBehavior
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../autocomplete/AbstractAutoCompleteBehavior.java | 2 +
.../html/autocomplete/AutoCompleteSettings.java | 54 ++++++++++++++++++++++
.../html/autocomplete/wicket-autocomplete.js | 9 +++-
3 files changed, 64 insertions(+), 1 deletion(-)
(wicket) 04/04: Renamed the TabBehavior to KeyTabBehavior
Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
adelbene pushed a commit to branch wicket-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
commit d0c8035fd2b4b49d6f8110d563c3b940960c09d4
Author: Erik Strid <er...@idainfront.se>
AuthorDate: Sun Nov 24 10:39:23 2024 +0100
Renamed the TabBehavior to KeyTabBehavior
---
.../autocomplete/AbstractAutoCompleteBehavior.java | 4 ++--
.../html/autocomplete/AutoCompleteSettings.java | 21 +++++++++++----------
.../markup/html/autocomplete/wicket-autocomplete.js | 2 +-
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
index 7b766b7a89..166b9fea1e 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
@@ -187,8 +187,8 @@ public abstract class AbstractAutoCompleteBehavior extends AbstractDefaultAjaxBe
{
sb.append(",className: '").append(settings.getCssClassName()).append('\'');
}
- sb.append(",tabBehavior: '").append(
- settings.getTabBehavior().getValue()).append('\'');
+ sb.append(",keyTabBehavior: '").append(
+ settings.getKeyTabBehavior().getValue()).append('\'');
sb.append('}');
return sb.toString();
}
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
index d243350f76..010846686a 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
@@ -74,7 +74,7 @@ public final class AutoCompleteSettings implements IClusterable
private int minInputLength = 1;
- private TabBehavior tabBehavior = TabBehavior.SELECT_FOCUS_NEXT_ELEMENT;
+ private KeyTabBehavior keyTabBehavior = KeyTabBehavior.SELECT_FOCUS_NEXT_ELEMENT;
/**
* Indicates whether the first item in the list is automatically selected when the autocomplete
@@ -384,25 +384,25 @@ public final class AutoCompleteSettings implements IClusterable
/**
* Indicates how the Tab key should be handled when having an item in the autocomplete list
- * selected, {@link TabBehavior#SELECT_FOCUS_NEXT_ELEMENT} is the default behavior.
+ * selected, {@link KeyTabBehavior#SELECT_FOCUS_NEXT_ELEMENT} is the default behavior.
*
* @return the behavior that should be used when the Tab key is pressed
*/
- public TabBehavior getTabBehavior()
+ public KeyTabBehavior getKeyTabBehavior()
{
- return tabBehavior;
+ return keyTabBehavior;
}
/**
* Set how the Tab key should be handled when having an item in the autocomplete list selected.
*
- * @param tabSelectBehavior the behavior that should be used when the Tab key is pressed,
- * {@link TabBehavior#SELECT_FOCUS_NEXT_ELEMENT} is the default behavior
+ * @param keyTabBehavior the behavior that should be used when the Tab key is pressed,
+ * {@link KeyTabBehavior#SELECT_FOCUS_NEXT_ELEMENT} is the default behavior
* @return this {@link AutoCompleteSettings}
*/
- public AutoCompleteSettings setTabBehavior(TabBehavior tabSelectBehavior)
+ public AutoCompleteSettings setKeyTabBehavior(KeyTabBehavior keyTabBehavior)
{
- this.tabBehavior = tabSelectBehavior;
+ this.keyTabBehavior = keyTabBehavior;
return this;
}
@@ -410,7 +410,8 @@ public final class AutoCompleteSettings implements IClusterable
* A behavior that can be used to control how the Tab key should be handled when having an item
* in the autocomplete list is marked.
*/
- public enum TabBehavior {
+ public enum KeyTabBehavior
+ {
/**
* Select the currently marked item and move the focus to the next focusable element.
*/
@@ -422,7 +423,7 @@ public final class AutoCompleteSettings implements IClusterable
private final String value;
- TabBehavior(String value)
+ KeyTabBehavior(String value)
{
this.value = value;
}
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
index 7f338fb7cd..fb91147f45 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
@@ -184,7 +184,7 @@
hideAutoComplete();
- if (cfg.tabBehavior === 'selectFocusAutocompleteInput' && keyCode === KEY_TAB) {
+ if (cfg.keyTabBehavior === 'selectFocusAutocompleteInput' && keyCode === KEY_TAB) {
// prevent moving focus to the next component if an item in the dropdown is selected
// using the Tab key
jqEvent.preventDefault();
(wicket) 03/04: Change the solution to use an enum to make the code clearer and make it easier to add more behaviours later
Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
adelbene pushed a commit to branch wicket-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
commit fc290a0aff934a49c279bbca0174b0e6c23b0369
Author: Erik Strid <er...@idainfront.se>
AuthorDate: Fri Nov 22 15:46:12 2024 +0100
Change the solution to use an enum to make the code clearer and make it easier to add more behaviours later
---
.../autocomplete/AbstractAutoCompleteBehavior.java | 3 +-
.../html/autocomplete/AutoCompleteSettings.java | 49 ++++++++++++++++------
.../html/autocomplete/wicket-autocomplete.js | 2 +-
3 files changed, 40 insertions(+), 14 deletions(-)
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
index 9b7c86b2bd..7b766b7a89 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
@@ -187,7 +187,8 @@ public abstract class AbstractAutoCompleteBehavior extends AbstractDefaultAjaxBe
{
sb.append(",className: '").append(settings.getCssClassName()).append('\'');
}
- sb.append(",focusInputOnTabSelection: ").append(settings.shouldFocusInputOnTabSelection());
+ sb.append(",tabBehavior: '").append(
+ settings.getTabBehavior().getValue()).append('\'');
sb.append('}');
return sb.toString();
}
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
index f07e932fad..d243350f76 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
@@ -74,7 +74,7 @@ public final class AutoCompleteSettings implements IClusterable
private int minInputLength = 1;
- private boolean focusInputOnTabSelection = false;
+ private TabBehavior tabBehavior = TabBehavior.SELECT_FOCUS_NEXT_ELEMENT;
/**
* Indicates whether the first item in the list is automatically selected when the autocomplete
@@ -384,27 +384,52 @@ public final class AutoCompleteSettings implements IClusterable
/**
* Indicates how the Tab key should be handled when having an item in the autocomplete list
- * selected.
+ * selected, {@link TabBehavior#SELECT_FOCUS_NEXT_ELEMENT} is the default behavior.
*
- * @return <code>true</code> if the focus should return to the input field, <code>false</code>
- * moves the focus to the next component.
+ * @return the behavior that should be used when the Tab key is pressed
*/
- public boolean shouldFocusInputOnTabSelection()
+ public TabBehavior getTabBehavior()
{
- return focusInputOnTabSelection;
+ return tabBehavior;
}
/**
- * Set how the tab key should be handled when having an item in the autocomplete list selected.
+ * Set how the Tab key should be handled when having an item in the autocomplete list selected.
*
- * @param focusInputOnTabSelection <code>true</code> if the focus should return to the input
- * field when the Tab key pressed, <code>false</code> is the default which moves the focus to
- * the next component.
+ * @param tabSelectBehavior the behavior that should be used when the Tab key is pressed,
+ * {@link TabBehavior#SELECT_FOCUS_NEXT_ELEMENT} is the default behavior
* @return this {@link AutoCompleteSettings}
*/
- public AutoCompleteSettings setFocusInputOnTabSelection(boolean focusInputOnTabSelection)
+ public AutoCompleteSettings setTabBehavior(TabBehavior tabSelectBehavior)
{
- this.focusInputOnTabSelection = focusInputOnTabSelection;
+ this.tabBehavior = tabSelectBehavior;
return this;
}
+
+ /**
+ * A behavior that can be used to control how the Tab key should be handled when having an item
+ * in the autocomplete list is marked.
+ */
+ public enum TabBehavior {
+ /**
+ * Select the currently marked item and move the focus to the next focusable element.
+ */
+ SELECT_FOCUS_NEXT_ELEMENT("selectFocusNextElement"),
+ /**
+ * Select the currently marked item and move the focus to the auto complete input field.
+ */
+ SELECT_FOCUS_INPUT("selectFocusAutocompleteInput");
+
+ private final String value;
+
+ TabBehavior(String value)
+ {
+ this.value = value;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+ }
}
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
index 2b1426bb78..7f338fb7cd 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
@@ -184,7 +184,7 @@
hideAutoComplete();
- if (cfg.focusInputOnTabSelection && keyCode === KEY_TAB) {
+ if (cfg.tabBehavior === 'selectFocusAutocompleteInput' && keyCode === KEY_TAB) {
// prevent moving focus to the next component if an item in the dropdown is selected
// using the Tab key
jqEvent.preventDefault();
(wicket) 01/04: Added ability to prevent autocomplete to move focus to the next component when selecting an item using the tab key in the autocomplete list
Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
adelbene pushed a commit to branch wicket-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
commit c05d4b8f70527607fe60847d9fd2b6acffdb17f1
Author: Erik Strid <er...@idainfront.se>
AuthorDate: Wed Nov 20 06:49:02 2024 +0100
Added ability to prevent autocomplete to move focus to the next component when selecting an item using the tab key in the autocomplete list
---
.../autocomplete/AbstractAutoCompleteBehavior.java | 1 +
.../html/autocomplete/AutoCompleteSettings.java | 28 ++++++++++++++++++++++
.../html/autocomplete/wicket-autocomplete.js | 4 ++++
3 files changed, 33 insertions(+)
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
index 6e9db0f21b..9b7c86b2bd 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
@@ -187,6 +187,7 @@ public abstract class AbstractAutoCompleteBehavior extends AbstractDefaultAjaxBe
{
sb.append(",className: '").append(settings.getCssClassName()).append('\'');
}
+ sb.append(",focusInputOnTabSelection: ").append(settings.shouldFocusInputOnTabSelection());
sb.append('}');
return sb.toString();
}
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
index c9c43ceac8..f07e932fad 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteSettings.java
@@ -74,6 +74,8 @@ public final class AutoCompleteSettings implements IClusterable
private int minInputLength = 1;
+ private boolean focusInputOnTabSelection = false;
+
/**
* Indicates whether the first item in the list is automatically selected when the autocomplete
* list is shown.
@@ -379,4 +381,30 @@ public final class AutoCompleteSettings implements IClusterable
this.minInputLength = minInputLength;
return this;
}
+
+ /**
+ * Indicates how the Tab key should be handled when having an item in the autocomplete list
+ * selected.
+ *
+ * @return <code>true</code> if the focus should return to the input field, <code>false</code>
+ * moves the focus to the next component.
+ */
+ public boolean shouldFocusInputOnTabSelection()
+ {
+ return focusInputOnTabSelection;
+ }
+
+ /**
+ * Set how the tab key should be handled when having an item in the autocomplete list selected.
+ *
+ * @param focusInputOnTabSelection <code>true</code> if the focus should return to the input
+ * field when the Tab key pressed, <code>false</code> is the default which moves the focus to
+ * the next component.
+ * @return this {@link AutoCompleteSettings}
+ */
+ public AutoCompleteSettings setFocusInputOnTabSelection(boolean focusInputOnTabSelection)
+ {
+ this.focusInputOnTabSelection = focusInputOnTabSelection;
+ return this;
+ }
}
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
index 2b2998e60d..89f46e32ef 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
@@ -169,6 +169,10 @@
}
break;
case KEY_TAB:
+ if (cfg.focusInputOnTabSelection && selected > -1) {
+ // prevent moving focus to the next component if an item in the dropdown is selected
+ jqEvent.preventDefault();
+ }
case KEY_ENTER:
ignoreKeyEnter = false;
(wicket) 02/04: Fix jshint issues
Posted by ad...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
adelbene pushed a commit to branch wicket-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
commit d227133b22837ef806dc0a5b2fd053b68de814a7
Author: Erik Strid <er...@idainfront.se>
AuthorDate: Thu Nov 21 07:55:25 2024 +0100
Fix jshint issues
---
.../ajax/markup/html/autocomplete/wicket-autocomplete.js | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
index 89f46e32ef..2b1426bb78 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
@@ -126,7 +126,8 @@
});
Wicket.Event.add(obj, 'keydown', function (jqEvent) {
- switch(Wicket.Event.keyCode(jqEvent)){
+ var keyCode = Wicket.Event.keyCode(jqEvent);
+ switch (keyCode) {
case KEY_UP:
if (elementCount > 0) {
if (selected>-1) {
@@ -169,10 +170,6 @@
}
break;
case KEY_TAB:
- if (cfg.focusInputOnTabSelection && selected > -1) {
- // prevent moving focus to the next component if an item in the dropdown is selected
- jqEvent.preventDefault();
- }
case KEY_ENTER:
ignoreKeyEnter = false;
@@ -187,6 +184,12 @@
hideAutoComplete();
+ if (cfg.focusInputOnTabSelection && keyCode === KEY_TAB) {
+ // prevent moving focus to the next component if an item in the dropdown is selected
+ // using the Tab key
+ jqEvent.preventDefault();
+ }
+
ignoreKeyEnter = true;
} else if (Wicket.AutoCompleteSettings.enterHidesWithNoSelection) {
hideAutoComplete();