Browse Source

Update ComboBox popup position comparison to use correct top value. (#12041)

Fixes #12029
tags/8.12.0.alpha1
Anna Koskinen 3 years ago
parent
commit
797b49372f
No account linked to committer's email address

+ 2
- 2
client/src/main/java/com/vaadin/client/ui/VComboBox.java View 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();

+ 1
- 1
uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayout.java View 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);

+ 35
- 0
uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayoutTest.java View 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);
}

}

Loading…
Cancel
Save