Browse Source

Fix combo box suggestion popup height (#10256)

Fixes #10214
tags/8.2.0.alpha3
Adam Wagner 6 years ago
parent
commit
ffe1e0c022

+ 11
- 3
client/src/main/java/com/vaadin/client/ui/VComboBox.java View File

@@ -867,10 +867,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

+ 25
- 0
uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxHeight.java View File

@@ -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<String> comboBox = new ComboBox<>();
comboBox.setPageLength(0);
comboBox.setItems(
IntStream.range(0, 100)
.mapToObj(i -> "Item number " + String.valueOf(i))
.collect(Collectors.toList()));

addComponent(comboBox);
}
}

+ 4
- 0
uitest/src/main/themes/VAADIN/themes/tests-valo-combobox-height/_variables.scss View File

@@ -0,0 +1,4 @@
$v-selection-overlay-padding-vertical: 10px;
$v-selection-overlay-padding-horizontal: 10px;

@import "../valo/valo";

+ 13
- 0
uitest/src/main/themes/VAADIN/themes/tests-valo-combobox-height/styles.scss View File

@@ -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;
}
}

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

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

Loading…
Cancel
Save