]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make clicking outside a ComboBox add a pending new item (#18366)
authorArtur Signell <artur@vaadin.com>
Mon, 10 Oct 2016 19:58:04 +0000 (22:58 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 11 Nov 2016 20:51:21 +0000 (20:51 +0000)
It should not matter how you move from a field to the next. Tabbing
to the next field already previously caused the new item handler to
be invoked. This fixes the case when you click in the next field to
work the same way.

Change-Id: I3978d87cde8f05dce92edda2a4a116f4a15e0749

client/src/main/java/com/vaadin/client/ui/VFilterSelect.java
uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java

index 2eeff9ece2e9628a7203a58ca63950fc833ad744..38e067658bd43f317d1e3fb657eec654874e65aa 100644 (file)
@@ -2376,6 +2376,9 @@ public class VFilterSelect extends Composite
 
         focused = false;
         if (!readonly) {
+            if (textInputEnabled && allowNewItem) {
+                suggestionPopup.menu.doSelectedItemAction();
+            }
             if (selectedOptionKey == null) {
                 if (explicitSelectedCaption != null) {
                     setPromptingOff(explicitSelectedCaption);
index 9d5d307e10c9290332b34724bb1944e8be2b58fe..5cf901a04eae6b7bc62be819d9bb9917b3f4228b 100644 (file)
@@ -64,6 +64,14 @@ public class ComboBoxSelectingWithNewItemsAllowedTest extends MultiBrowserTest {
         assertThatSelectedValueIs("a");
     }
 
+    @Test
+    public void itemIsAddedWhenClickingOutside() {
+        clearInputAndType("foo");
+        findElement(By.tagName("body")).click();
+        assertOneMoreThanInitial();
+        assertThatSelectedValueIs("foo");
+    }
+
     @Test
     public void matchingSuggestionIsSelectedWithEnter() {
         typeInputAndHitEnter("a0");
@@ -122,14 +130,14 @@ public class ComboBoxSelectingWithNewItemsAllowedTest extends MultiBrowserTest {
     }
 
     @Test
-    public void noSelectionAfterMouseOut() {
+    public void selectionOnMouseOut() {
         typeInputAndHitEnter("a20");
         comboBoxElement.sendKeys(Keys.ARROW_DOWN, Keys.ARROW_DOWN);
 
         findElement(By.className("v-app")).click();
 
         assertInitialItemCount();
-        assertThatSelectedValueIs("a20");
+        assertThatSelectedValueIs("a21");
     }
 
     @Test