]> source.dussan.org Git - vaadin-framework.git/commitdiff
Recalculate the column widths before the first row is added (#11609)
authorZhe Sun <31067185+ZheSun88@users.noreply.github.com>
Thu, 6 Jun 2019 05:45:02 +0000 (08:45 +0300)
committerGitHub <noreply@github.com>
Thu, 6 Jun 2019 05:45:02 +0000 (08:45 +0300)
* Recalculate the column widths before the first row is added

Fixes #11607

client/src/main/java/com/vaadin/client/widgets/Grid.java
uitest/reference-screenshots/chrome/CheckboxAlignmentWithNoHeaderGridTest-alignments_are_correct_ANY_Chrome__alignment.png [new file with mode: 0644]
uitest/src/main/java/com/vaadin/tests/components/grid/CheckboxAlignmentWithNoHeaderGrid.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/grid/CheckboxAlignmentWithNoHeaderGridTest.java [new file with mode: 0644]

index ae63749c5f2aa50e9dc43c43adf098186b9a3ca2..4c88879ad10cc0a9246f102e9a074738e887b0e8 100755 (executable)
@@ -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 (file)
index 0000000..81c821b
Binary files /dev/null and b/uitest/reference-screenshots/chrome/CheckboxAlignmentWithNoHeaderGridTest-alignments_are_correct_ANY_Chrome__alignment.png 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 (file)
index 0000000..303f865
--- /dev/null
@@ -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 (file)
index 0000000..a800d9b
--- /dev/null
@@ -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");
+    }
+}