]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make clicking outside a ComboBox add a pending new item (#18366)
authorAleksi Hietanen <aleksi@vaadin.com>
Tue, 29 Nov 2016 13:46:06 +0000 (15:46 +0200)
committerPekka Hyvönen <pekka@vaadin.com>
Fri, 9 Dec 2016 07:39:00 +0000 (09:39 +0200)
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

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

index 0b7724f3d0afdac33845854101c33e09f920faa3..29e4aa006f4051786cb9921808122215db4cf362 100644 (file)
@@ -2381,6 +2381,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 b568ecf912f358e3c3cef1e5c8c7a9ff720d9ef8..c16a80856b9a5b1b5aeda2c9c285a259f74fe887 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