]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix scrolling problem in table in Chrome 56+ (#10492)
authorArtur <artur@vaadin.com>
Fri, 5 Jan 2018 13:13:55 +0000 (15:13 +0200)
committerOlli Tietäväinen <ollit@vaadin.com>
Fri, 5 Jan 2018 13:13:55 +0000 (15:13 +0200)
* Fix scrolling problem in table in Chrome 56+

Fixes #8707

* Remove commented code

themes/src/main/themes/VAADIN/themes/base/table/table.scss
themes/src/main/themes/VAADIN/themes/valo/components/_table.scss
uitest/src/main/java/com/vaadin/tests/components/table/TableScrollsOnRefresh.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/table/TableScrollsOnRefreshTest.java [new file with mode: 0644]

index 22ffdffa4de0d8a8f4768f7645ebd5bfe3c23fe3..64f700c882f5a0391f0fec27fc407894c1cda105 100644 (file)
 }
 .#{$primaryStyleName}-body {
        border: 1px solid #aaa;
+       overflow-anchor: none; /* In Chrome 56+ */
 }
 .#{$primaryStyleName}-row-spacer {
        height: 10px;
index 86efb966375a13df92e20652fec3f6704e121fcc..82435a4d416c71dd8772d0a59f3aaca1a5c85f73 100644 (file)
@@ -279,6 +279,7 @@ $v-table-background-color: null !default;
 
   .#{$primary-stylename}-body {
     border: $v-table-border-width solid $border-color;
+    overflow-anchor: none; /* In Chrome 56+ */
     @include user-select(text);
   }
 
diff --git a/uitest/src/main/java/com/vaadin/tests/components/table/TableScrollsOnRefresh.java b/uitest/src/main/java/com/vaadin/tests/components/table/TableScrollsOnRefresh.java
new file mode 100644 (file)
index 0000000..962f24f
--- /dev/null
@@ -0,0 +1,75 @@
+package com.vaadin.tests.components.table;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
+
+public class TableScrollsOnRefresh extends AbstractTestUIWithLog {
+    private Table table = new Table(
+            "scroll down table, so it loads next page, and then click 'refresh' button");
+    private Button refresh = new Button("refresh");
+    private BeanItemContainer<TableItem> container = new BeanItemContainer<TableItem>(
+            TableItem.class);
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        refresh.addClickListener(new Button.ClickListener() {
+
+            @Override
+            public void buttonClick(Button.ClickEvent event) {
+                table.refreshRowCache();
+            }
+        });
+        table.setSizeFull();
+        VerticalLayout vl = new VerticalLayout(refresh, table);
+        vl.setExpandRatio(table, 1f);
+        vl.setSizeFull();
+        setContent(vl);
+        table.setContainerDataSource(container);
+        populateContainer();
+    }
+
+    private void populateContainer() {
+        List<TableItem> items = new ArrayList<TableItem>();
+        for (int i = 0; i < 1000; i++) {
+            items.add(new TableItem("Item " + Integer.toString(i),
+                    "Item description " + Integer.toString(i)));
+
+        }
+        container.addAll(items);
+    }
+
+    public class TableItem {
+
+        private String name;
+        private String description;
+
+        public TableItem(String name, String description) {
+            this.name = name;
+            this.description = description;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public String getDescription() {
+            return description;
+        }
+
+        public void setDescription(String description) {
+            this.description = description;
+        }
+
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/table/TableScrollsOnRefreshTest.java b/uitest/src/test/java/com/vaadin/tests/components/table/TableScrollsOnRefreshTest.java
new file mode 100644 (file)
index 0000000..b078d00
--- /dev/null
@@ -0,0 +1,48 @@
+package com.vaadin.tests.components.table;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.TableElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class TableScrollsOnRefreshTest extends MultiBrowserTest {
+
+    @Test
+    public void ensureNoScrolling() throws InterruptedException {
+        openTestURL();
+        TableElement table = $(TableElement.class).first();
+        table.scroll(10000);
+        sleep(500); // wait for both data requests
+        String firstCellText = getFirstVisibleCell(table).getText();
+
+        ButtonElement refresh = $(ButtonElement.class).first();
+        refresh.click();
+        sleep(500); // wait for both data requests
+        Assert.assertEquals(firstCellText,
+                getFirstVisibleCell(table).getText());
+
+        refresh.click();
+        sleep(500); // wait for both data requests
+        Assert.assertEquals(firstCellText,
+                getFirstVisibleCell(table).getText());
+    }
+
+    private WebElement getFirstVisibleCell(TableElement table) {
+        int tableBodyTop = table.findElement(By.className("v-table-body"))
+                .getLocation().getY();
+        List<WebElement> cells = table
+                .findElements(By.className("v-table-cell-content"));
+        for (WebElement cell : cells) {
+            if (cell.getLocation().getY() > tableBodyTop) {
+                return cell;
+            }
+        }
+        return null;
+    }
+}