]> source.dussan.org Git - vaadin-framework.git/commitdiff
Select last item only if filtered items exist. (#18441)
authorSauli Tähkäpää <sauli@vaadin.com>
Thu, 9 Jul 2015 10:27:49 +0000 (13:27 +0300)
committerVaadin Code Review <review@vaadin.com>
Thu, 16 Jul 2015 06:40:11 +0000 (06:40 +0000)
Change-Id: I1b601f7bcddd3a62edcd97651a3270b79dacc7fd

client/src/com/vaadin/client/ui/VFilterSelect.java
uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigation.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/combobox/ComboBoxEmptyItemsKeyboardNavigationTest.java [new file with mode: 0644]

index 7951759fa21075cb9d9aafbca6f3cdc711baf092..1e474d3a1f9549035de97bbf9867fbf0dfd9476c 100644 (file)
@@ -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 (file)
index 0000000..2f96724
--- /dev/null
@@ -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 (file)
index 0000000..c5cbc5e
--- /dev/null
@@ -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