aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhe Sun <31067185+ZheSun88@users.noreply.github.com>2019-06-06 08:45:02 +0300
committerGitHub <noreply@github.com>2019-06-06 08:45:02 +0300
commite80358a39130face6eeeccf68a6c81782a710105 (patch)
tree46c0326992816c663583f22b094edd4907201475
parent81277c29711c4821df76be9067588a3dfd93a7db (diff)
downloadvaadin-framework-e80358a39130face6eeeccf68a6c81782a710105.tar.gz
vaadin-framework-e80358a39130face6eeeccf68a6c81782a710105.zip
Recalculate the column widths before the first row is added (#11609)
* Recalculate the column widths before the first row is added Fixes #11607
-rwxr-xr-xclient/src/main/java/com/vaadin/client/widgets/Grid.java8
-rw-r--r--uitest/reference-screenshots/chrome/CheckboxAlignmentWithNoHeaderGridTest-alignments_are_correct_ANY_Chrome__alignment.pngbin0 -> 20652 bytes
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/CheckboxAlignmentWithNoHeaderGrid.java49
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/CheckboxAlignmentWithNoHeaderGridTest.java37
4 files changed, 94 insertions, 0 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java
index ae63749c5f..4c88879ad1 100755
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -7220,6 +7220,14 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
if (newSize > oldSize) {
+ if (oldSize == 0 && !isHeaderVisible()) {
+ // Fixes framework/issues/11607
+ // Need to recalculate column widths when the
+ // first row is added to a non-header grid,
+ // otherwise the checkbox will be aligned in a
+ // wrong place.
+ recalculateColumnWidths();
+ }
body.insertRows(oldSize, newSize - oldSize);
cellFocusHandler.rowsAddedToBody(Range
.withLength(oldSize, newSize - oldSize));
diff --git a/uitest/reference-screenshots/chrome/CheckboxAlignmentWithNoHeaderGridTest-alignments_are_correct_ANY_Chrome__alignment.png b/uitest/reference-screenshots/chrome/CheckboxAlignmentWithNoHeaderGridTest-alignments_are_correct_ANY_Chrome__alignment.png
new file mode 100644
index 0000000000..81c821bffd
--- /dev/null
+++ b/uitest/reference-screenshots/chrome/CheckboxAlignmentWithNoHeaderGridTest-alignments_are_correct_ANY_Chrome__alignment.png
Binary files differ
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/CheckboxAlignmentWithNoHeaderGrid.java b/uitest/src/main/java/com/vaadin/tests/components/grid/CheckboxAlignmentWithNoHeaderGrid.java
new file mode 100644
index 0000000000..303f8651b0
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/CheckboxAlignmentWithNoHeaderGrid.java
@@ -0,0 +1,49 @@
+package com.vaadin.tests.components.grid;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.VerticalLayout;
+
+public class CheckboxAlignmentWithNoHeaderGrid extends AbstractTestUI {
+
+ List<String> items = new ArrayList<>();
+ int count = 1;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+
+ VerticalLayout lay = new VerticalLayout();
+
+ Grid<String> grid = new Grid<>();
+ grid.setSelectionMode(Grid.SelectionMode.MULTI);
+ grid.setHeaderVisible(false);
+ grid.addColumn(Object::toString);
+
+ grid.setItems(items);
+
+ lay.addComponent(grid);
+ lay.addComponent(new Button("add", e -> {
+ items.add("ABCDEFG" + count);
+ grid.getDataProvider().refreshAll();
+ count++;
+ }));
+ addComponent(lay);
+
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Rows added to empty grid with multiselect and no header should not break ";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 11607;
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/CheckboxAlignmentWithNoHeaderGridTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/CheckboxAlignmentWithNoHeaderGridTest.java
new file mode 100644
index 0000000000..a800d9b0ec
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/CheckboxAlignmentWithNoHeaderGridTest.java
@@ -0,0 +1,37 @@
+package com.vaadin.tests.components.grid;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class CheckboxAlignmentWithNoHeaderGridTest extends SingleBrowserTest {
+
+ GridElement grid;
+
+ @Before
+ public void init() {
+ openTestURL();
+ grid = $(GridElement.class).first();
+ }
+
+ @Test
+ public void alignments_are_correct() throws IOException {
+ Assert.assertTrue("This should be an empty grid",
+ grid.getRowCount() == 0);
+
+ for (int i =0; i<5; i++) {
+ $(ButtonElement.class).first().click();
+ }
+ sleep(100);
+
+ Assert.assertTrue("This grid should have 5 rows",
+ grid.getRowCount() == 5);
+ compareScreen("alignment");
+ }
+}