From ef4a0bceb1d7d6cfd642bc1bd3a729b10b1584b3 Mon Sep 17 00:00:00 2001 From: Adam Wagner Date: Mon, 30 Oct 2017 13:31:27 +0200 Subject: [PATCH] Fix combo box suggestion popup height (#10256) Fixes #10214 --- .../java/com/vaadin/client/ui/VComboBox.java | 14 +++++-- .../components/combobox/ComboBoxHeight.java | 25 ++++++++++++ .../_variables.scss | 4 ++ .../tests-valo-combobox-height/styles.scss | 13 +++++++ .../combobox/ComboBoxHeightTest.java | 38 +++++++++++++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxHeight.java create mode 100644 uitest/src/main/themes/VAADIN/themes/tests-valo-combobox-height/_variables.scss create mode 100644 uitest/src/main/themes/VAADIN/themes/tests-valo-combobox-height/styles.scss create mode 100644 uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxHeightTest.java 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 784f2b116d..25172eea4a 100644 --- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java +++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java @@ -854,10 +854,18 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, menuHeight -= up.getOffsetHeight() + down.getOffsetHeight() + status.getOffsetHeight(); } else { - final ComputedStyle s = new ComputedStyle( + final ComputedStyle menuStyle = new ComputedStyle( menu.getElement()); - menuHeight -= s.getIntProperty("marginBottom") - + s.getIntProperty("marginTop"); + final ComputedStyle popupStyle = new ComputedStyle( + suggestionPopup.getElement()); + menuHeight -= menuStyle.getIntProperty("marginBottom") + + menuStyle.getIntProperty("marginTop") + + menuStyle.getIntProperty("paddingBottom") + + menuStyle.getIntProperty("paddingTop") + + popupStyle.getIntProperty("marginBottom") + + popupStyle.getIntProperty("marginTop") + + popupStyle.getIntProperty("paddingBottom") + + popupStyle.getIntProperty("paddingTop"); } // If the available page height is really tiny then this will be diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxHeight.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxHeight.java new file mode 100644 index 0000000000..ba6956dc22 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxHeight.java @@ -0,0 +1,25 @@ +package com.vaadin.tests.components.combobox; + +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class ComboBoxHeight extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + ComboBox comboBox = new ComboBox<>(); + comboBox.setPageLength(0); + comboBox.setItems( + IntStream.range(0, 100) + .mapToObj(i -> "Item number " + String.valueOf(i)) + .collect(Collectors.toList())); + + addComponent(comboBox); + } +} diff --git a/uitest/src/main/themes/VAADIN/themes/tests-valo-combobox-height/_variables.scss b/uitest/src/main/themes/VAADIN/themes/tests-valo-combobox-height/_variables.scss new file mode 100644 index 0000000000..d4c7111398 --- /dev/null +++ b/uitest/src/main/themes/VAADIN/themes/tests-valo-combobox-height/_variables.scss @@ -0,0 +1,4 @@ +$v-selection-overlay-padding-vertical: 10px; +$v-selection-overlay-padding-horizontal: 10px; + +@import "../valo/valo"; diff --git a/uitest/src/main/themes/VAADIN/themes/tests-valo-combobox-height/styles.scss b/uitest/src/main/themes/VAADIN/themes/tests-valo-combobox-height/styles.scss new file mode 100644 index 0000000000..6b3926dcf6 --- /dev/null +++ b/uitest/src/main/themes/VAADIN/themes/tests-valo-combobox-height/styles.scss @@ -0,0 +1,13 @@ +@import "variables"; +@import "../tests-valo/valotest"; + +.tests-valo-combobox-height { + @include valotest; + + .v-filterselect-suggestpopup { + margin-top: 10px !important; + margin-bottom: 10px; + padding-top: 5px; + padding-bottom: 5px; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxHeightTest.java b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxHeightTest.java new file mode 100644 index 0000000000..512238b759 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxHeightTest.java @@ -0,0 +1,38 @@ +package com.vaadin.tests.components.combobox; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class ComboBoxHeightTest extends SingleBrowserTest { + + @Test + public void testPopupHeight() { + openTestURL(); + assertPopupHeight(); + } + + @Test + public void testPopupHeightCustomTheme() { + openTestURL("theme=tests-valo-combobox-height"); + assertPopupHeight(); + } + + private void assertPopupHeight() { + ComboBoxElement comboBox = $(ComboBoxElement.class).first(); + + comboBox.openPopup(); + WebElement suggestionPopup = comboBox.getSuggestionPopup(); + + int suggestionPopupBottom = + suggestionPopup.getLocation().getY() + suggestionPopup.getSize() + .getHeight(); + + assertGreaterOrEqual( + "Combo box suggestion popup should not exceed the browser's viewport", + driver.manage().window().getSize().getHeight(), + suggestionPopupBottom); + } +} -- 2.39.5