summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSauli Tähkäpää <sauli@vaadin.com>2015-07-09 13:27:49 +0300
committerTeemu Suo-Anttila <teemusa@vaadin.com>2015-07-21 14:41:29 +0300
commitcfe6f81edaed74e63385b0031d4fc7f6e21b308b (patch)
tree3923f7bbda9695d384e5a2029ecbaba0531cf772
parent3cb0d071f1f36b55ad95fd2c51fc5576d4f45cb3 (diff)
downloadvaadin-framework-cfe6f81edaed74e63385b0031d4fc7f6e21b308b.tar.gz
vaadin-framework-cfe6f81edaed74e63385b0031d4fc7f6e21b308b.zip
Select last item only if filtered items exist. (#18441)
Change-Id: I8fcf93e807f90c297b0bc4a8820a88ff5a58aeca
-rw-r--r--client/src/com/vaadin/client/ui/VFilterSelect.java4
-rw-r--r--uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigation.java15
-rw-r--r--uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java30
3 files changed, 48 insertions, 1 deletions
diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java
index 7951759fa2..1e474d3a1f 100644
--- a/client/src/com/vaadin/client/ui/VFilterSelect.java
+++ b/client/src/com/vaadin/client/ui/VFilterSelect.java
@@ -417,7 +417,9 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
selectPrevPage();
} else {
- selectItem(menu.getItems().get(menu.getItems().size() - 1));
+ if(!menu.getItems().isEmpty()) {
+ selectLastItem();
+ }
}
}
diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigation.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigation.java
new file mode 100644
index 0000000000..2f96724db1
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigation.java
@@ -0,0 +1,15 @@
+package com.vaadin.tests.components.combobox;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxEmptyItemsKeyboardNavigation extends AbstractTestUI {
+ @Override
+ protected void setup(VaadinRequest request) {
+ ComboBox comboBox = new ComboBox();
+ comboBox.addItems("foo", "bar");
+
+ addComponent(comboBox);
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java
new file mode 100644
index 0000000000..c5cbc5eea6
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java
@@ -0,0 +1,30 @@
+package com.vaadin.tests.components.combobox;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.collection.IsEmptyCollection.empty;
+
+import java.util.List;
+
+import org.junit.Test;
+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.newelements.ComboBoxElement;
+
+public class ComboBoxEmptyItemsKeyboardNavigationTest extends MultiBrowserTest {
+
+ @Test
+ public void navigatingUpOnAnEmptyMenuDoesntThrowErrors() {
+ setDebug(true);
+ openTestURL();
+
+ ComboBoxElement combobox = $(ComboBoxElement.class).first();
+ combobox.sendKeys("a", Keys.ARROW_UP);
+
+ List<WebElement> errors = findElements(By.className("SEVERE"));
+
+ assertThat(errors, empty());
+ }
+} \ No newline at end of file