diff options
3 files changed, 106 insertions, 8 deletions
diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java index 516fe5e9b3..230c9e6639 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -254,7 +254,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, /** * Shows the popup where the user can see the filtered options - * + * * @param currentSuggestions * The filtered suggestions * @param currentPage @@ -345,7 +345,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, /** * Should the next page button be visible to the user? - * + * * @param active */ private void setNextButtonActive(boolean active) { @@ -365,7 +365,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, /** * Should the previous page button be visible to the user - * + * * @param active */ private void setPrevButtonActive(boolean active) { @@ -554,7 +554,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, * amount of items are visible at a time and a scrollbar or buttons are * visible to change page. If paging is turned of then all options are * rendered into the popup menu. - * + * * @param paging * Should the paging be turned on? */ @@ -679,7 +679,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, /** * Was the popup just closed? - * + * * @return true if popup was just closed */ public boolean isJustClosed() { @@ -708,7 +708,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, /** * Updates style names in suggestion popup to help theme building. - * + * * @param uidl * UIDL for the whole combo box * @param componentState @@ -799,7 +799,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, /** * Sets the suggestions rendered in the menu - * + * * @param suggestions * The suggestions to be rendered in the menu */ @@ -1784,10 +1784,14 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, if (!allowNewItem) { /* * New items are not allowed: If there is only one - * suggestion, select that. Otherwise do nothing. + * suggestion, select that. If there is more than one + * suggestion Enter key should work as Escape key. Otherwise + * do nothing. */ if (currentSuggestions.size() == 1) { onSuggestionSelected(currentSuggestions.get(0)); + } else if (currentSuggestions.size() > 1) { + reset(); } } else { // Handle addition of new items. diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSuggestionPopupClose.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSuggestionPopupClose.java new file mode 100644 index 0000000000..253d6a0d1e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSuggestionPopupClose.java @@ -0,0 +1,29 @@ +package com.vaadin.tests.components.combobox; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; + +public class ComboBoxSuggestionPopupClose extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final ComboBox select = new ComboBox("ComboBox"); + select.addItem("one"); + select.addItem("two"); + select.addItem("three"); + addComponent(select); + } + + @Override + protected String getTestDescription() { + return "Closing the suggestion popup using Enter key is " + + "broken in combobox when opening popup using Enter " + + "key and not changin the selection using arrows"; + } + + @Override + protected Integer getTicketNumber() { + return 14379; + } +} diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSuggestionPopupCloseTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSuggestionPopupCloseTest.java new file mode 100644 index 0000000000..5e9e076cac --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSuggestionPopupCloseTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.combobox; + +import static org.junit.Assert.assertFalse; +import static org.openqa.selenium.Keys.ARROW_DOWN; +import static org.openqa.selenium.Keys.ENTER; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * @author Vaadin Ltd + */ +public class ComboBoxSuggestionPopupCloseTest extends MultiBrowserTest { + + private WebElement selectTextbox; + + @Test + public void closeSuggestionPopupTest() throws Exception { + openTestURL(); + + waitForElementVisible(By.className("v-filterselect")); + + selectTextbox = $(ComboBoxElement.class).first().findElement( + By.vaadin("#textbox")); + selectTextbox.click(); + + // open popup and select first element + sendKeys(new Keys[] { ARROW_DOWN, ARROW_DOWN, ENTER }); + + // open popup and hit enter to close it + sendKeys(new Keys[] { ARROW_DOWN, ENTER }); + + assertFalse(isElementPresent(By.className("v-filterselect-suggestmenu"))); + + } + + private void sendKeys(Keys[] keys) throws Exception { + for (Keys key : keys) { + selectTextbox.sendKeys(key); + // wait a while between the key presses, at least PhantomJS fails if + // they are sent too fast + sleep(10); + } + } +}; |