diff --git a/client/src/main/java/com/vaadin/client/ui/VComboBox.java b/client/src/main/java/com/vaadin/client/ui/VComboBox.java index 6ff2f31a9a4..b0799303644 100644 --- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java +++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java @@ -906,7 +906,7 @@ public void setPosition(int offsetWidth, int offsetHeight) { // 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 void setPosition(int offsetWidth, int offsetHeight) { } // Only update the position if it has changed. - if (top != topPosition || left != getPopupLeft()) { + if (top != getAbsoluteTop() || left != getPopupLeft()) { setPopupPosition(left, top); } menu.scrollSelectionIntoView(); diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayout.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayout.java index 5c619bafc44..6a15de38761 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayout.java +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayout.java @@ -13,7 +13,7 @@ public class ComboBoxAtBottomEdgeWithinHorizontalLayout extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { ComboBox 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); diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayoutTest.java index f169e56ab5f..f3da49fe754 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayoutTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayoutTest.java @@ -3,6 +3,7 @@ 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 void ensurePopupInView() { 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); + } + }