diff options
author | Anastasia Smirnova <anasmi@utu.fi> | 2019-02-25 11:49:20 +0200 |
---|---|---|
committer | Sun Zhe <31067185+ZheSun88@users.noreply.github.com> | 2019-02-25 11:49:20 +0200 |
commit | 6cc773fb7c717328fbce7255fa419581b7609a92 (patch) | |
tree | b133c3d03fb2be689bcf25a53759ad47c3934891 | |
parent | 19f839154e49c487ff9d156e962acb4df889a553 (diff) | |
download | vaadin-framework-6cc773fb7c717328fbce7255fa419581b7609a92.tar.gz vaadin-framework-6cc773fb7c717328fbce7255fa419581b7609a92.zip |
Ensure pop-up is not opened, when tabbing out fast from Combobox (#11436)
Checking that no prior Combobox behavior is broken
* Cleaning-up the code
Adding UI test
* Adding TestBench test
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/VComboBox.java | 13 | ||||
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxFastTabbingOut.java | 43 |
2 files changed, 52 insertions, 4 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VComboBox.java b/client/src/main/java/com/vaadin/client/ui/VComboBox.java index f80927ec1d..6ddb2cd29a 100644 --- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java +++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java @@ -1454,7 +1454,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, if (!waitingForFilteringResponse && suggestionPopup.isAttached()) { showPopup = true; } - if (showPopup) { + // Don't show popup, if is not focused + if (showPopup && focused) { suggestionPopup.showSuggestions(currentPage); } @@ -1750,7 +1751,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, /** For internal use only. May be removed or replaced in the future. */ public boolean focused = false; - + /** For internal use only. May be removed or replaced in the future. */ + public boolean noKeyDownEvents = true; /** * If set to false, the component should not allow entering text to the * field even for filtering. @@ -2198,6 +2200,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, return; } + noKeyDownEvents = false; if (suggestionPopup.isAttached()) { if (enableDebug) { debug("Keycode " + keyCode + " target is popup"); @@ -2307,7 +2310,8 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, // queue this, may be cancelled by selection int selectedIndex = suggestionPopup.menu.getSelectedIndex(); - if (!allowNewItems && selectedIndex != -1) { + if (!allowNewItems && selectedIndex != -1 + && !currentSuggestions.isEmpty()) { onSuggestionSelected(currentSuggestions.get(selectedIndex)); } else { dataReceivedHandler.reactOnInputWhenReady(tb.getText()); @@ -2371,7 +2375,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, // NOP break; default: - if (textInputEnabled) { + if (textInputEnabled && !noKeyDownEvents) { // when filtering, we always want to see the results on the // first page first. filterOptions(0); @@ -2514,6 +2518,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, return; } + noKeyDownEvents = true; focused = true; updatePlaceholder(); addStyleDependentName("focus"); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxFastTabbingOut.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxFastTabbingOut.java new file mode 100644 index 0000000000..1789f3ba85 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboboxFastTabbingOut.java @@ -0,0 +1,43 @@ +package com.vaadin.tests.components.combobox; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; + +import java.util.ArrayList; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class ComboboxFastTabbingOut extends AbstractTestUI { + @Override + protected void setup(VaadinRequest request) { + ComboBox<String> combobox = new ComboBox<>( + "Press any letter and tab out fast. The pop-up should stay closed"); + ArrayList<String> values = new ArrayList<>(); + values.add("AMERICAN SAMOA"); + values.add("ANTIGUA AND BARBUDA"); + values.add("Bali"); + combobox.setId("firstCombobox"); + combobox.setItems(values); + + ComboBox<String> combobox2 = new ComboBox<>( + "Focusing after tabbing from another CB should not open the pop-up"); + + combobox2.setItems("AMERICAN SAMOA", "ANTIGUA AND BARBUDA", "Lake 1", + "Lake 2"); + combobox2.setId("secondCombobox"); + addComponent(combobox); + addComponent(combobox2); + } + + @Override + protected String getTestDescription() { + return "On tabbing out fast, the popup window stays closed"; + } + + @Override + protected Integer getTicketNumber() { + return 11354; + } + +} |