From 3f97add7d89064a734b231de2cffac467a53fcab Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 10 Oct 2016 22:58:04 +0300 Subject: [PATCH] Make clicking outside a ComboBox add a pending new item (#18366) 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 --- .../java/com/vaadin/client/ui/VFilterSelect.java | 3 +++ .../ComboBoxSelectingWithNewItemsAllowedTest.java | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client/src/main/java/com/vaadin/client/ui/VFilterSelect.java b/client/src/main/java/com/vaadin/client/ui/VFilterSelect.java index 2eeff9ece2..38e067658b 100644 --- a/client/src/main/java/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/main/java/com/vaadin/client/ui/VFilterSelect.java @@ -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); 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 9d5d307e10..5cf901a04e 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 @@ -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 -- 2.39.5