diff options
author | Artur Signell <artur@vaadin.com> | 2016-01-01 12:02:06 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-01-07 08:19:02 +0000 |
commit | af15d54e5a49491ebadb9748381a22239ebf8ff7 (patch) | |
tree | 14875bb93410404ef361faf959d526d6949ae412 | |
parent | 86969a99c2c3ac0389912dceaf3bad9477717fb1 (diff) | |
download | vaadin-framework-af15d54e5a49491ebadb9748381a22239ebf8ff7.tar.gz vaadin-framework-af15d54e5a49491ebadb9748381a22239ebf8ff7.zip |
Fixes exception when enter is pressed and there is nothing to select (#19149)
Change-Id: I8ff11e98bb4ec999d369ff5bcde0cb95290ed037
-rw-r--r-- | client/src/com/vaadin/client/ui/VFilterSelect.java | 12 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java | 44 |
2 files changed, 52 insertions, 4 deletions
diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java index 99ebde1910..9459cc14a6 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -1861,8 +1861,16 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, case KeyCodes.KEY_ENTER: if (!allowNewItem) { - onSuggestionSelected(currentSuggestions - .get(suggestionPopup.menu.getSelectedIndex())); + int selected = suggestionPopup.menu.getSelectedIndex(); + if (selected != -1) { + onSuggestionSelected(currentSuggestions.get(selected)); + } else { + // The way VFilterSelect is done, it handles enter and tab + // in exactly the same way so we close the popup in both + // cases even though we could leave it open when pressing + // enter + suggestionPopup.hide(); + } } else { // Handle addition of new items. suggestionPopup.menu.doSelectedItemAction(); diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java index c5cbc5eea6..ebf6ba4773 100644 --- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java @@ -10,10 +10,11 @@ import org.openqa.selenium.Keys; import org.openqa.selenium.WebElement; import com.vaadin.testbench.By; -import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.SingleBrowserTestPhantomJS2; import com.vaadin.tests.tb3.newelements.ComboBoxElement; -public class ComboBoxEmptyItemsKeyboardNavigationTest extends MultiBrowserTest { +public class ComboBoxEmptyItemsKeyboardNavigationTest extends + SingleBrowserTestPhantomJS2 { @Test public void navigatingUpOnAnEmptyMenuDoesntThrowErrors() { @@ -27,4 +28,43 @@ public class ComboBoxEmptyItemsKeyboardNavigationTest extends MultiBrowserTest { assertThat(errors, empty()); } + + @Test + public void selectingUsingEnterInAnEmptyMenu() { + setDebug(true); + openTestURL(); + + ComboBoxElement combobox = $(ComboBoxElement.class).first(); + combobox.sendKeys("a", Keys.ENTER); + + List<WebElement> errors = findElements(By.className("SEVERE")); + + assertThat(errors, empty()); + + assertPopupClosed(combobox); + } + + @Test + public void selectingUsingTabInAnEmptyMenu() { + setDebug(true); + openTestURL(); + + ComboBoxElement combobox = $(ComboBoxElement.class).first(); + // The joy of testing, one tab should be enough but is not (it is + // locally), two tabs does the trick for PhantomJS on the cluster... + combobox.sendKeys("abc", Keys.TAB, Keys.TAB); + + List<WebElement> errors = findElements(By.className("SEVERE")); + + assertThat(errors, empty()); + assertPopupClosed(combobox); + } + + private void assertPopupClosed(ComboBoxElement combobox) { + org.openqa.selenium.By bySuggestionPopup = By.vaadin("#popup"); + + assertThat("ComboBox popup should not be open", + combobox.findElements(bySuggestionPopup).isEmpty()); + + } }
\ No newline at end of file |