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

// ComboBox itself may be incorrectly positioned, don't try to // ComboBox itself may be incorrectly positioned, don't try to
// adjust horizontal popup position yet. Earlier width // adjust horizontal popup position yet. Earlier width
// calculations must be performed anyway to avoid flickering. // calculations must be performed anyway to avoid flickering.
if (top != topPosition) {
if (top != getAbsoluteTop()) {
// Variable 'left' still contains the original popupLeft, // Variable 'left' still contains the original popupLeft,
// 'top' has been updated, thus vertical position needs // 'top' has been updated, thus vertical position needs
// adjusting. // adjusting.
} }


// Only update the position if it has changed. // Only update the position if it has changed.
if (top != topPosition || left != getPopupLeft()) {
if (top != getAbsoluteTop() || left != getPopupLeft()) {
setPopupPosition(left, top); setPopupPosition(left, top);
} }
menu.scrollSelectionIntoView(); menu.scrollSelectionIntoView();

+ 1
- 1
uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayout.java View File

@Override @Override
protected void setup(VaadinRequest request) { protected void setup(VaadinRequest request) {
ComboBox<Integer> comboBox = new ComboBox<>(); 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 horizontalLayout = new HorizontalLayout();
horizontalLayout.addComponent(comboBox); horizontalLayout.addComponent(comboBox);

+ 35
- 0
uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxAtBottomEdgeWithinHorizontalLayoutTest.java View File

import org.junit.Test; import org.junit.Test;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;


import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ComboBoxElement; import com.vaadin.testbench.elements.ComboBoxElement;
import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.tests.tb3.MultiBrowserTest;


cbBottom, popupBottom), cbBottom, popupBottom); 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