]> source.dussan.org Git - vaadin-framework.git/commitdiff
Update ComboBox popup position comparison to use correct top value. (#12041)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Fri, 26 Jun 2020 12:50:51 +0000 (15:50 +0300)
committerGitHub <noreply@github.com>
Fri, 26 Jun 2020 12:50:51 +0000 (15:50 +0300)
Fixes #12029

client/src/main/java/com/vaadin/client/ui/VComboBox.java
uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayout.java
uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayoutTest.java

index 6ff2f31a9a44c60849966502cd62d0598b298518..b07993036440ea487c7f47828e331cd8eae5fd08 100644 (file)
@@ -906,7 +906,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
                 // ComboBox itself may be incorrectly positioned, don't try to
                 // adjust horizontal popup position yet. Earlier width
                 // calculations must be performed anyway to avoid flickering.
-                if (top != topPosition) {
+                if (top != getAbsoluteTop()) {
                     // Variable 'left' still contains the original popupLeft,
                     // 'top' has been updated, thus vertical position needs
                     // adjusting.
@@ -935,7 +935,7 @@ public class VComboBox extends Composite implements Field, KeyDownHandler,
             }
 
             // Only update the position if it has changed.
-            if (top != topPosition || left != getPopupLeft()) {
+            if (top != getAbsoluteTop() || left != getPopupLeft()) {
                 setPopupPosition(left, top);
             }
             menu.scrollSelectionIntoView();
index 5c619bafc44bc3d2ef6ecf90e08839390d8559c1..6a15de387617e2477cf01cb70047138978820f84 100644 (file)
@@ -13,7 +13,7 @@ public class ComboBoxAtBottomEdgeWithinHorizontalLayout extends AbstractTestUI {
     @Override
     protected void setup(VaadinRequest request) {
         ComboBox<Integer> comboBox = new ComboBox<>();
-        comboBox.setItems(Arrays.asList(100, 200, 300, 400, 500));
+        comboBox.setItems(Arrays.asList(102, 205, 302, 402, 500));
 
         HorizontalLayout horizontalLayout = new HorizontalLayout();
         horizontalLayout.addComponent(comboBox);
index f169e56ab5f5038ecced63c5c522f5d1a3b81588..f3da49fe754e4eb49aba891a5c023a7fc1cc19e2 100644 (file)
@@ -3,6 +3,7 @@ package com.vaadin.tests.components.combobox;
 import org.junit.Test;
 import org.openqa.selenium.WebElement;
 
+import com.vaadin.testbench.By;
 import com.vaadin.testbench.elements.ComboBoxElement;
 import com.vaadin.tests.tb3.MultiBrowserTest;
 
@@ -26,4 +27,38 @@ public class ComboBoxAtBottomEdgeWithinHorizontalLayoutTest
                 cbBottom, popupBottom), cbBottom, popupBottom);
     }
 
+    @Test
+    public void ensurePopupPositionUpdatesWhenFiltered() {
+        openTestURL();
+
+        ComboBoxElement cb = $(ComboBoxElement.class).first();
+        cb.openPopup();
+        WebElement popup = cb.getSuggestionPopup();
+
+        int initialTop = popup.getLocation().getY();
+
+        // filter a bit
+        cb.findElement(By.vaadin("#textbox")).sendKeys("2");
+        int updatedTop = popup.getLocation().getY();
+        assertLessThan(String.format(
+                "Popup should be repositioned when "
+                        + "filtered. Initial: %s, Updated: %s",
+                initialTop, updatedTop), initialTop, updatedTop);
+        int cbBottom = cb.getLocation().getY() + cb.getSize().getHeight();
+        assertGreaterOrEqual(String.format(
+                "Popup should still open above the ComboBox when "
+                        + "filtered a bit. ComboBox: %s, Popup: %s",
+                cbBottom, updatedTop), cbBottom, updatedTop);
+
+        // filter more
+        cb.clear();
+        cb.findElement(By.vaadin("#textbox")).sendKeys("1");
+        popup = cb.getSuggestionPopup();
+        updatedTop = popup.getLocation().getY();
+        assertLessThanOrEqual(String.format(
+                "Popup should open below the ComboBox when "
+                        + "filtered down to one result. ComboBox: %s, Popup: %s",
+                cbBottom, updatedTop), cbBottom, updatedTop);
+    }
+
 }