Browse Source

Recalculate the column widths before the first row is added (#11609)

* Recalculate the column widths before the first row is added

Fixes #11607
tags/8.9.0.alpha1
Zhe Sun 4 years ago
parent
commit
e80358a391
No account linked to committer's email address

+ 8
- 0
client/src/main/java/com/vaadin/client/widgets/Grid.java View File

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

BIN
uitest/reference-screenshots/chrome/CheckboxAlignmentWithNoHeaderGridTest-alignments_are_correct_ANY_Chrome__alignment.png View File


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

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

}

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

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

Loading…
Cancel
Save