Browse Source

Add styling for ComponentRenderer wrapper div (#9691)

Fixes #9170
tags/8.1.0.rc2
Teemu Suo-Anttila 6 years ago
parent
commit
7b288aeb66

+ 3
- 1
client/src/main/java/com/vaadin/client/connectors/grid/ComponentRendererConnector.java View File

@@ -43,7 +43,9 @@ public class ComponentRendererConnector

@Override
public SimplePanel createWidget() {
return GWT.create(SimplePanel.class);
SimplePanel panel = GWT.create(SimplePanel.class);
panel.setStyleName("component-wrap");
return panel;
}

@Override

+ 1
- 0
documentation/components/components-grid.asciidoc View File

@@ -621,6 +621,7 @@ grid.addColumn(person -> {
}, new ComponentRenderer());
----

[classname]#Components# in [classname]#Grid# [classname]#ComponentRenderer# are wrapped in a [literal]#++div++# with the style name [literal]#++component-wrap++#. This can be used to style the alignment and size of the [classname]#Component#.

[[components.grid.renderer.custom]]
=== Custom Renderers

+ 5
- 0
themes/src/main/themes/VAADIN/themes/valo/components/_grid.scss View File

@@ -222,6 +222,11 @@ $v-grid-details-border-bottom-stripe: 1px solid darken($v-grid-row-background-co
}
}
}

// Style for ComponentRenderer wrap
div.component-wrap {
width: 100%;
}
}

// Rows

+ 1
- 0
uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java View File

@@ -35,6 +35,7 @@ public class GridComponents extends AbstractTestUIWithLog {

TextField textField = new TextField();
textField.setValue(string);
textField.setWidth("100%");
// Make sure all changes are sent immediately
textField.setValueChangeMode(ValueChangeMode.EAGER);
textField.addValueChangeListener(e -> {

+ 16
- 0
uitest/src/test/java/com/vaadin/tests/components/grid/GridComponentsTest.java View File

@@ -7,6 +7,7 @@ import org.openqa.selenium.WebElement;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.GridElement.GridCellElement;
import com.vaadin.testbench.elements.GridElement.GridRowElement;
import com.vaadin.testbench.elements.NotificationElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
@@ -55,6 +56,21 @@ public class GridComponentsTest extends MultiBrowserTest {
assertRowExists(5, "Row 1005");
}

@Test
public void testTextFieldSize() {
openTestURL();
GridCellElement cell = $(GridElement.class).first().getCell(0, 1);
int cellWidth = cell.getSize().getWidth();
int fieldWidth = cell.findElement(By.tagName("input")).getSize()
.getWidth();
// padding left and right, +1 to fix sub pixel issues
int padding = 18 * 2 + 1;

int extraSpace = Math.abs(fieldWidth - cellWidth);
Assert.assertTrue("Too much unused space in cell. Expected: " + padding
+ " Actual: " + extraSpace, extraSpace <= padding);
}

private void editTextFieldInCell(GridElement grid, int row, int col) {
WebElement textField = grid.getCell(row, col)
.findElement(By.tagName("input"));

Loading…
Cancel
Save