summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-07-17 14:08:30 +0300
committerHenri Sara <henri.sara@gmail.com>2017-07-17 14:08:30 +0300
commit01a453649e1c4ace5ea1e2b8dcf18102a639d0f1 (patch)
tree62121fcbb1f3627801286876f778fec36f9173b4
parent6c61a9797ce364cc706eb468605512b7d6d537cd (diff)
downloadvaadin-framework-01a453649e1c4ace5ea1e2b8dcf18102a639d0f1.tar.gz
vaadin-framework-01a453649e1c4ace5ea1e2b8dcf18102a639d0f1.zip
Fix combobox adding new items on blur (#9660)
Fixes #9071
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VComboBox.java12
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java16
2 files changed, 26 insertions, 2 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 45e69cee01..61e9b46e68 100644
--- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java
+++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java
@@ -2489,11 +2489,19 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
focused = false;
updatePlaceholder();
+ removeStyleDependentName("focus");
+
+ // Send new items when clicking out with the mouse.
if (!readonly) {
- reset();
+ if (textInputEnabled && allowNewItems
+ && (currentSuggestion == null || tb.getText().equals(
+ currentSuggestion.getReplacementString()))) {
+ dataReceivedHandler.reactOnInputWhenReady(tb.getText());
+ } else {
+ reset();
+ }
suggestionPopup.hide();
}
- removeStyleDependentName("focus");
connector.sendBlurEvent();
}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java
index 0765c2781a..d61bb26dad 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java
@@ -21,6 +21,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import com.vaadin.testbench.By;
@@ -65,6 +66,14 @@ public class ComboBoxSelectingWithNewItemsAllowedTest extends MultiBrowserTest {
}
@Test
+ public void itemIsAddedWithClickOut() {
+ typeInputAndClickOut("a");
+
+ assertOneMoreThanInitial();
+ assertThatSelectedValueIs("a");
+ }
+
+ @Test
public void matchingSuggestionIsSelectedWithEnter() {
typeInputAndHitEnter("a0");
@@ -204,6 +213,13 @@ public class ComboBoxSelectingWithNewItemsAllowedTest extends MultiBrowserTest {
sendKeysToInput(Keys.TAB);
}
+ private void typeInputAndClickOut(String input) {
+ clearInputAndType(input);
+ new Actions(getDriver()).moveToElement(comboBoxElement, 10, 10)
+ .moveByOffset(comboBoxElement.getSize().getWidth(), 0).click()
+ .perform();
+ }
+
private void clearInputAndType(String input) {
comboBoxElement.clear();
sendKeysToInput(input);