Skip to content

Commit

Permalink
Update ComboBox popup position comparison to use correct top value. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansku committed Jun 26, 2020
1 parent d824efe commit 797b493
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 2 additions & 2 deletions client/src/main/java/com/vaadin/client/ui/VComboBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

}

0 comments on commit 797b493

Please sign in to comment.